Skip to content

Modernize legacy code for PHP 8.1 and repo conventions - #1028

Merged
mglaman merged 1 commit into
mainfrom
audit/3-modernization
Sep 9, 2026
Merged

Modernize legacy code for PHP 8.1 and repo conventions#1028
mglaman merged 1 commit into
mainfrom
audit/3-modernization

Conversation

@mglaman

@mglaman mglaman commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Part 7 of 9 in the legacy-code audit stack. Mechanical modernization with no behavior change.

What changed

  • declare(strict_types=1) in the remaining src/ files (the Reflection classes, RecursiveExtensionFilterIterator, DeprecatedHookImplementation).
  • The four bundled Drupal-core forks in src/Drupal/ are marked @internal — they are bootstrap implementation details, not extension points.
  • The six audited concrete rules are final, matching the newer rules.
  • Promoted readonly constructors and typed properties across the audited classes; the dead splFileInfo property is gone.
  • The per-node rebuilt arrays in DiscouragedFunctionsRule and GlobalDrupalDependencyInjectionRule are class constants now.
  • ::class over string FQCNs, str_contains/str_starts_with/str_ends_with over strpos/substr, and the @method isDir() docblock shim replaced with an explicit $this->current()->isDir().
  • Extension::parseInfo() validates that Yaml::parse() returned an array.
  • phpcs.xml raises php_version from 7.4 to 8.1 to match composer.json, so PHPCS actually checks against the supported platform.

Upgrade note

Six rule classes are now final: DiscouragedFunctionsRule, GlobalDrupalDependencyInjectionRule, LoadIncludes, ModuleLoadInclude, PluginManagerInspectionRule, and PluginManagerSetsCacheBackendRule. The rules never carried an API promise, but a project that subclassed one of them will need to copy the rule instead.

Testing

Full suite, self-analysis, and phpcs (with the raised php_version) are green.

🤖 Generated with Claude Code

@mglaman
mglaman force-pushed the audit/3-modernization branch from fe2c0b6 to 868eafb Compare August 5, 2026 16:20
@mglaman
mglaman force-pushed the audit/3-modernization branch from 868eafb to 828bd42 Compare August 5, 2026 16:44
@mglaman
mglaman force-pushed the audit/3-modernization branch from 828bd42 to 13ff201 Compare August 5, 2026 17:15
@mglaman
mglaman force-pushed the audit/3-modernization branch from 13ff201 to 3bdc910 Compare August 5, 2026 19:13
@mglaman
mglaman force-pushed the audit/3-modernization branch from 3bdc910 to 1035692 Compare August 5, 2026 19:33
@mglaman
mglaman force-pushed the audit/3-modernization branch 2 times, most recently from f746a98 to 6a8b779 Compare September 8, 2026 18:14
@mglaman
mglaman force-pushed the audit/3-modernization branch 2 times, most recently from c6250b0 to 41a184f Compare September 8, 2026 18:27
@mglaman
mglaman force-pushed the audit/3-modernization branch from 41a184f to 31c1261 Compare September 8, 2026 18:59
@mglaman
mglaman force-pushed the audit/3-modernization branch 2 times, most recently from 66b9bad to 447d228 Compare September 8, 2026 19:47
Base automatically changed from audit/2-api-conventions to main September 9, 2026 01:07
- declare(strict_types=1) in the remaining src/ files (Reflection
  classes, RecursiveExtensionFilterIterator, DeprecatedHookImplementation).
- Mark the four bundled Drupal-core forks in src/Drupal/ as @internal.
- final on the six audited concrete rules, matching newer rules.
- Promoted readonly constructors and typed properties in the audited
  rules, reflections, Extension, DrupalServiceDefinition, and
  DrupalAutoloader; drop the dead splFileInfo property.
- Class constants for the per-node rebuilt arrays in
  DiscouragedFunctionsRule and GlobalDrupalDependencyInjectionRule.
- ::class instead of string FQCNs where the class is imported.
- str_contains/str_starts_with/str_ends_with over strpos/substr.
- Replace the RecursiveFilterIterator __call shim (@method isDir) with
  an explicit $this->current()->isDir() call.
- Validate Yaml::parse() output in Extension::parseInfo().
- phpcs.xml: raise php_version from 7.4 to 8.1 so PHPCS checks against
  the actual composer platform requirement.
- Drop the self-namespace use in ExtensionDiscovery and fix the
  dcorating_service_id typo in ServiceMap.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mglaman
mglaman force-pushed the audit/3-modernization branch from 447d228 to 73c6aaf Compare September 9, 2026 01:07
@mglaman
mglaman marked this pull request as ready for review September 9, 2026 14:17
@mglaman
mglaman merged commit f981141 into main Sep 9, 2026
19 of 20 checks passed
@mglaman
mglaman deleted the audit/3-modernization branch September 9, 2026 14:55
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