Skip to content

[DEVX-6509] PHP Modernization - to get ahead of future PHP releases, hopefully#2770

Open
namespacebrian wants to merge 12 commits into
4.xfrom
php85
Open

[DEVX-6509] PHP Modernization - to get ahead of future PHP releases, hopefully#2770
namespacebrian wants to merge 12 commits into
4.xfrom
php85

Conversation

@namespacebrian
Copy link
Copy Markdown
Contributor

No description provided.

@greg-1-anderson greg-1-anderson changed the title Php85 [DEVX-6509] Php85 Jan 30, 2026
@wiz-inc-b08cf2810f
Copy link
Copy Markdown

wiz-inc-b08cf2810f Bot commented Feb 2, 2026

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities 1 Medium
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Software Management Finding Software Management Findings -
Total 1 Medium

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

Phase 1 - Static Analysis:
- Update PHP requirement from >=7.4 to >=8.2 (aligns with runtime check)
- Add PHPStan 2.1 with deprecation-rules extension
- Create phpstan.neon configuration at level 1
- Generate baseline for 35 existing issues
- Add composer scripts: phpstan, phpstan:baseline
- Fix missing return statement in CommitAndPushCommand

Phase 2 - Unit Tests:
- Create tests/Unit directory structure
- Add phpunit.unit.xml configuration for fast local tests
- Create UnitTestCase base class with helper methods
- Add 68 unit tests for core components:
  - RequestOperationResult (12 tests)
  - TerminusConfig (18 tests)
  - TerminusModel (16 tests)
  - TerminusCollection (22 tests)
- Add composer scripts: test:unit, test:quick
Phase 3 - PHP Deprecation Remediation:

RequestOperationResult.php:
- Add declare(strict_types=1)
- Remove #[\ReturnTypeWillChange] attributes
- Replace dynamic property access with match expressions
- Add proper return types to ArrayAccess methods
- Add explicit mixed type to $data property

Fix implicit nullable parameters (~15 files):
- DocBlock.php: ?string $comment
- LocalMachineHelper.php: ?callable $callback
- ProcessProgressBar.php: ?callable $callback
- TerminusConfig.php: mixed $defaultOverride
- DefaultsConfig.php: ?string $current_dir
- Backups.php: ?string $element (2 methods)
- TerminusModel.php: mixed $attributes
- Workflow.php, AddOnModel.php, Plan.php, SiteTrait.php: mixed $attributes

PHP 8.5 Support:
- Update bin/terminus to allow PHP 8.5 (block 8.6+)
- Verified all unit tests pass on PHP 8.5.2
- No deprecation warnings
Phase 4 type system hardening for TerminusModel and related classes:

- Add declare(strict_types=1) to TerminusModel
- Add typed properties to TerminusModel ($id, $attributes, $collection, $url, $date_attributes)
- Add return types to all TerminusModel methods (fetch, get, has, set, serialize, etc.)
- Propagate property types to all Model subclasses ($url, $date_attributes)
- Add return types to overridden methods in all Model subclasses:
  - getUrl(): string
  - getReferences(): array
  - serialize(): array
  - parseAttributes(object $data): object
- Update Friend traits and interfaces with proper return types:
  - SiteTrait, EnvironmentTrait, SiteJoinTrait, UserJoinTrait, OrganizationJoinTrait
  - SiteJoinInterface, UserJoinInterface, OrganizationJoinInterface
- Update test ConcreteTestModel with typed properties

All 68 unit tests pass and PHPStan reports no errors.
Phase 4 type system hardening for TerminusCollection and related classes:

- Add declare(strict_types=1) to TerminusCollection
- Add typed properties to TerminusCollection ($data, $collected_class, $models)
- Add return types to all TerminusCollection methods
- Propagate $collected_class string type to all 28 Collection subclasses
- Add return types to overridden methods in Collection subclasses:
  - fetch(): static
  - getData(): array
  - serialize(): array
  - ids(): array
  - add(object, array): TerminusModel
- Fix SiteMetricsTrait serialize() return type
- Update test ConcreteTestCollection with typed properties

All 68 unit tests pass and PHPStan reports no errors.
Phase 4 type system hardening for TerminusCommand:

- Add declare(strict_types=1)
- Add return types to all methods:
  - log(): LoggerInterface
  - io(): TerminusStyle
  - confirm(string, array): bool
- Remove unnecessary null coalesce on typed string parameter

All 68 unit tests pass and PHPStan reports no errors.
… Request

- src/Helpers/ (17 files): Add declare(strict_types=1), property types,
  and return types to all helper classes including AliasEmitters,
  CommandCoverageReport, LocalMachineHelper, Traits, and Utility classes
- src/Exceptions/ (5 files): Add declare(strict_types=1), property types,
  and return types to TerminusException and all subclasses
- src/Config/ (6 files): Add declare(strict_types=1) and return types to
  TerminusConfig, ConfigAwareTrait, and config subclasses
- src/Request/ (4 files): Add declare(strict_types=1), property types,
  and return types to Request and RequestAware classes

Part of PHP 8.5 modernization work - Phase 4 type system hardening.
The preg_match() function requires its second argument to be a string,
but $response->getStatusCode() returns an integer. This caused a
TypeError in PHP 8.x strict mode:

  preg_match(): Argument #2 ($subject) must be of type string, int given

Cast the status code to string before passing to preg_match().
The uniqid() function requires its prefix argument to be a string,
but $model_data->id can be an integer. This caused a TypeError in
PHP 8.x strict mode:

  uniqid(): Argument #1 ($prefix) must be of type string, int given

Cast the id to string before passing to uniqid().
@namespacebrian namespacebrian changed the title [DEVX-6509] Php85 [DEVX-6509] PHP Modernization - to get ahead of future PHP releases, hopefully Feb 2, 2026
The $id property is typed as ?string but the API can return integer IDs.
Cast to string when assigning from attributes to fix:

  Cannot assign int to property TerminusModel::$id of type ?string
The function can receive strings, not just arrays. Change type from
?array to mixed to match the original behavior which had an is_array
check for this reason.
@namespacebrian namespacebrian marked this pull request as ready for review February 2, 2026 20:38
@namespacebrian namespacebrian requested a review from a team as a code owner February 2, 2026 20:38
Comment thread tests/Unit/Collections/CLAUDE.md Outdated
* @param array<string, mixed> $methods Method name => return value pairs
* @return object The mock object
*/
protected function createMockWithMethods(string $className, array $methods = []): object
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used. 🏆

Resolves merge conflict in composer.json: keep php85's test:unit script
(tests/config/phpunit.unit.xml) and phpstan scripts over the slapdash
phpunit-unit.xml-at-root approach added to 4.x.

The 3 substantive tests added to 4.x (SecretsApi, VcsApi, WorkflowProcessingTrait)
are migrated into the php85 unit test structure:
- Moved to subdirectories mirroring src/ layout
- Extended UnitTestCase instead of TestCase directly
- SecretsApi/VcsApi tests updated to use TerminusConfig (required by
  strict return type added in php85 strict-types pass)
- SecretsApiTest uses callPrivateMethod() instead of inline ReflectionMethod

Dropped: empty CreateCommandTest (tests deleted when server-side validation
replaced the local validateRepositoryName() it was meant to cover).
Dropped: redundant root-level phpunit-unit.xml.

All 87 unit tests pass. 🤖
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.

2 participants