Skip to content

chore(php): native types + final class on legacy core (#1290) - #1296

Merged
rumblefrog merged 2 commits into
mainfrom
chore/1290-types-and-final
May 8, 2026
Merged

rumblefrog merged 2 commits into
mainfrom
chore/1290-types-and-final

Conversation

@rumblefrog

Copy link
Copy Markdown
Member

Summary

Closes part of #1290. Phases A + J from the umbrella issue:

Plus AGENTS.md anti-pattern + conventions rows, and a new "Native types over docblocks" subsection.

Notable decisions

  1. Database::execute() narrows from @return mixed to : bool — PHP's manual specifies PDOStatement::execute(): bool. With ATTR_ERRMODE = ERRMODE_EXCEPTION (set in our PDO bootstrap), the only return paths are true or thrown. Verified by reading every caller.
  2. Database::resultset() narrows to : array — fetchAll() returns array on PHP 8+ (the false legacy return only happens with ERRMODE_SILENT).
  3. AdminTabs::__construct Smarty type fix: Smarty $theme → \Smarty\Smarty $theme (matches Renderer.php's namespaced resolution). Removes 3 PHPStan baseline entries.
  4. Two new PHPStan baseline entries on admin.edit.admindetails.php:294 — legitimate code smells the better type inference unmasked (HasAccess(ADMIN_OWNER) || HasAccess(ADMIN_EDIT_ADMINS) || $_GET['id'] == GetAid() is always true given the early-return guard at lines 51-52). Out-of-scope for this PR — file as a follow-up against the page handler.

Closing invariants verified

$ rg '@param\s+\$|@param\s+\w+\s+\$|@return\s+\w' web/includes
# only View DTOs (generic shape refinements), CUserManager (3 methods deferred to #1295),
# Util/Duration (descriptive), Version, Api (generic refinements), PHPStan/SmartyTemplateRule,
# SteamID/** (third-party), auth/openid.php (third-party).

$ rg '^class\s+\w' web/includes
# only `class View` (abstract) + LightOpenID + 5 SteamID classes (all third-party).

Test plan

  • ./sbpp.sh phpstan clean
  • ./sbpp.sh test 388 tests pass (PR1's RoutingTest cases included)
  • ./sbpp.sh ts-check clean
  • ./sbpp.sh composer api-contract byte-identical
  • PHPStan baseline net -13 entries (15 removed, 2 added — both legitimate)

rumblefrog added 2 commits May 8, 2026 03:37
Phases A and J from #1290:
- A: native parameter / return types replacing @PARAM / @return
     docblocks across CUserManager, Database, Log, Auth, JWT, CSRF,
     Crypto, Api, ApiError, AdminTabs, Theme, Mailer, the auth
     handlers, Config, Host, system-functions.php. Coordinated with
     PR1's phase I — three CUserManager methods (is_logged_in,
     is_admin, HasAccess simplified branch) take their `: bool` from
     PR1 in the same commit they're simplified.
- J: `final class` on every legacy leaf that nothing extends. View
     stays abstract.

Plus AGENTS.md anti-pattern + conventions rows.

No functional change. PHPStan should infer better; baseline
shrinks (380 -> 371): 9 entries removed (Smarty class.notFound x3,
is_numeric.alreadyNarrowedType, mixed. parseError, deadCode.unreachable,
parameter.notFound on Log::getCount @PARAM $search, JWT private
method static call), 2 added (booleanOr.alwaysTrue +
rightAlwaysTrue on pages/admin.edit.admindetails.php — legitimate
findings the new types unmask). Coordinated with parallel PR1
(mechanical sweep) on CUserManager / Database / Api / auth handlers
— bodies are PR1's, signatures are this PR's.
- M1: type SmartyCustomFunctions.php (5 procedural plugin functions
      + remove legacy @PARAM shape docblocks).
- M2: type page-builder.php's route() and build() signatures.
- m1: Database::lastInsertId() narrows to string|false (matches the
      PHP manual; ?string $name parameter added).
- m2: Database::iterate() $fetchType parameter typed int (matches
      sibling resultset() / single()).
- m3: AGENTS.md "Native types over docblocks" prose tightened to
      add SmartyCustomFunctions.php / page-builder.php to the list
      and acknowledge CUserManager's three deferred methods.
- n1/n2/n3: tighten loose return types (SecondsToString : string;
      GetCommunityName : string; Log::getAll : array).

PHPStan + PHPUnit + api-contract still clean.
@rumblefrog
rumblefrog added this pull request to the merge queue May 8, 2026
Merged via the queue into main with commit e7fa1d4 May 8, 2026
4 checks passed
@rumblefrog
rumblefrog deleted the chore/1290-types-and-final branch May 8, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant