[DEVX-6509] PHP Modernization - to get ahead of future PHP releases, hopefully#2770
Open
namespacebrian wants to merge 12 commits into
Open
[DEVX-6509] PHP Modernization - to get ahead of future PHP releases, hopefully#2770namespacebrian wants to merge 12 commits into
namespacebrian wants to merge 12 commits into
Conversation
Wiz Scan Summary
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().
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.
3 tasks
| * @param array<string, mixed> $methods Method name => return value pairs | ||
| * @return object The mock object | ||
| */ | ||
| protected function createMockWithMethods(string $className, array $methods = []): object |
greg-1-anderson
approved these changes
Feb 3, 2026
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. 🤖
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.