-
-
Notifications
You must be signed in to change notification settings - Fork 6
Fix CI pipeline: phpunit.xml validation warning, php-parser v4 test skip, and comprehensive type-analysis regression coverage #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
cdeace8
Initial plan
Copilot 1fae5be
test: add regression coverage for broken param phpdoc raw
Copilot f4f4072
test: expand broken phpdoc type regression coverage
Copilot d48c560
feat: recover coarse types from broken phpdoc
Copilot d22f7dd
refactor: keep phpdoc recovery and errors consistent
Copilot 5180aa4
chore: tighten phpdoc recovery exception handling
Copilot 6bc14a7
style: simplify phpdoc recovery token check
Copilot 75671f9
feat: add PHP 8.4 property hooks and asymmetric visibility support
Copilot 1d1d4fa
fix: skip hook params with error/empty names in PHPProperty
Copilot 9d4fe95
fix: resolve both CI failures (phpunit.xml warning + property-hooks t…
Copilot 5c3e936
test: expand Dummy8 blind-spot coverage (getPropertiesInfo, callable …
Copilot e466f5f
Add coverage for function and constant attributes
Copilot d034f80
Refine null-default parameter metadata assertions
Copilot 35bf8b8
Fix PHPStan and add PHP 8.4 fallback regression tests
Copilot 3833dc7
Deduplicate asymmetric visibility helper
Copilot 37b9ace
Stop promoted property scan after constructor
Copilot f315024
Fix promoted property CI regressions
Copilot 6fed600
Tighten promoted property merge logic
Copilot 72f1c78
Rename promoted parameter loop variable
Copilot 8f45db2
Exclude 8.4-only fixtures from v4 directory scans
Copilot d5eb4ca
Address property hook review feedback
Copilot cfd4ad0
Fix nullable null normalization edge case
Copilot d01b6b8
Reuse shared PHPClass autoload guard
Copilot 8b03fb1
Optimize broken phpdoc recovery retries
Copilot 9433ca1
Tighten phpdoc recovery token reuse
Copilot e95fe6f
Fix promoted property visibility merge
Copilot 29aa9bd
fix: phpstan/psalm annotations always win over plain @var/@return/@pa…
Copilot 00ed1ea
Fix two phpdoc type-parsing bugs: splitTypeAndVariable array-shape co…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,12 +58,9 @@ public function readObjectFromPhpNode($node, $dummy = null): self | |
| $this->attributes = Utils::extractAttributesFromAstNode($node->attrGroups); | ||
| } | ||
|
|
||
| // PHP < 8.2 raises an uncatchable E_COMPILE_ERROR for certain PHP 8.2+ syntax | ||
| // (standalone true/false/null types, DNF types, readonly class). Similarly, | ||
| // PHP < 8.3 raises an error for PHP 8.3+ syntax (typed class constants). | ||
| // Skip autoloading in those cases; AST data is still read from the node below. | ||
| $canAutoload = (\PHP_VERSION_ID >= 80200 || !self::nodeUsesPHP82PlusSyntax($node)) | ||
| && (\PHP_VERSION_ID >= 80300 || !self::nodeUsesPHP83PlusSyntax($node)); | ||
| // Skip autoloading when the current runtime cannot safely compile newer syntax; | ||
| // AST data is still read from the node below. | ||
| $canAutoload = self::canAutoloadFromPhpNode($node); | ||
| $classExists = false; | ||
| if ($canAutoload) { | ||
| try { | ||
|
|
@@ -122,6 +119,8 @@ public function readObjectFromPhpNode($node, $dummy = null): self | |
| } | ||
| } | ||
|
|
||
| $this->addPromotedPropertiesFromConstructor($node); | ||
|
|
||
| if (!empty($node->implements)) { | ||
| foreach ($node->implements as $interfaceObject) { | ||
| $interfaceFQN = $interfaceObject->toString(); | ||
|
|
@@ -462,101 +461,77 @@ private function readPhpDocProperties($doc): void | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the class node uses syntax that requires PHP 8.2+ and would | ||
| * cause an uncatchable E_COMPILE_ERROR when autoloaded on PHP < 8.2. | ||
| * | ||
| * @param Class_ $node | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function nodeUsesPHP82PlusSyntax(Class_ $node): bool | ||
| private function addPromotedPropertiesFromConstructor(Class_ $node): void | ||
| { | ||
| // readonly class is PHP 8.2+ | ||
| if ($node->isReadonly()) { | ||
| return true; | ||
| $method = $node->getMethod('__construct'); | ||
| if ($method === null) { | ||
| return; | ||
| } | ||
|
|
||
| foreach ($node->stmts as $stmt) { | ||
| if ($stmt instanceof \PhpParser\Node\Stmt\ClassMethod) { | ||
| if (self::containsPHP82PlusType($stmt->returnType)) { | ||
| return true; | ||
| } | ||
| foreach ($stmt->params as $param) { | ||
| if (self::containsPHP82PlusType($param->type)) { | ||
| return true; | ||
| } | ||
| } | ||
| } elseif ($stmt instanceof \PhpParser\Node\Stmt\Property) { | ||
| if (self::containsPHP82PlusType($stmt->type)) { | ||
| return true; | ||
| } | ||
| foreach ($method->params as $parameter) { | ||
| if (!self::isPromotedParameter($parameter)) { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| $parameterVar = $parameter->var; | ||
| if ( | ||
| !($parameterVar instanceof \PhpParser\Node\Expr\Variable) | ||
| || !\is_string($parameterVar->name) | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the class node uses syntax that requires PHP 8.3+ and would | ||
| * cause an uncatchable E_COMPILE_ERROR when autoloaded on PHP < 8.3. | ||
| * | ||
| * Covers: typed class constants (Stmt\ClassConst with a non-null type). | ||
| * | ||
| * @param Class_ $node | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function nodeUsesPHP83PlusSyntax(Class_ $node): bool | ||
| { | ||
| foreach ($node->stmts as $stmt) { | ||
| // Typed class constants are PHP 8.3+ | ||
| if ($stmt instanceof \PhpParser\Node\Stmt\ClassConst && $stmt->type !== null) { | ||
| return true; | ||
| $promotedProperty = (new PHPProperty($this->parserContainer)) | ||
| ->readObjectFromPromotedParam($parameter, $this->name); | ||
|
|
||
| $propertyName = $parameterVar->name; | ||
| $existingProperty = $this->properties[$propertyName] ?? null; | ||
| if ($existingProperty !== null) { | ||
| $this->mergePromotedPropertyData($existingProperty, $promotedProperty, $parameter); | ||
|
|
||
| continue; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| $this->properties[$propertyName] = $promotedProperty; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the given type node is a PHP 8.2+ type that causes an | ||
| * uncatchable E_COMPILE_ERROR when loaded on PHP < 8.2. | ||
| * | ||
| * Covers: standalone true/false/null types and DNF types (union of intersections). | ||
| * | ||
| * @param \PhpParser\Node|null $typeNode | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function containsPHP82PlusType($typeNode): bool | ||
| { | ||
| if ($typeNode === null) { | ||
| return false; | ||
| private function mergePromotedPropertyData( | ||
| PHPProperty $existingProperty, | ||
| PHPProperty $promotedProperty, | ||
| \PhpParser\Node\Param $parameter | ||
| ): void { | ||
| if ($promotedProperty->access !== '') { | ||
| $existingProperty->access = $promotedProperty->access; | ||
| } | ||
|
|
||
| // Standalone true, false, null as the *sole* type (not in a nullable like ?string) | ||
| // are PHP 8.2+ only. PHP-Parser represents these as Identifier nodes (not Name). | ||
| // Nullable null (?null) is syntactically invalid; NullableType wraps the inner type. | ||
| if ($typeNode instanceof \PhpParser\Node\Identifier) { | ||
| $name = \strtolower($typeNode->name); | ||
| return $name === 'true' || $name === 'false' || $name === 'null'; | ||
| if ($existingProperty->type === null && $promotedProperty->type !== null) { | ||
| $existingProperty->type = $promotedProperty->type; | ||
| } | ||
|
|
||
| // DNF types: union type containing an intersection type (PHP 8.2+) | ||
| if ($typeNode instanceof \PhpParser\Node\UnionType) { | ||
| foreach ($typeNode->types as $t) { | ||
| if ($t instanceof \PhpParser\Node\IntersectionType || self::containsPHP82PlusType($t)) { | ||
| return true; | ||
| } | ||
| } | ||
| if ($existingProperty->is_readonly === null && $promotedProperty->is_readonly !== null) { | ||
| $existingProperty->is_readonly = $promotedProperty->is_readonly; | ||
| } | ||
|
|
||
| if ($existingProperty->is_final === null && $promotedProperty->is_final !== null) { | ||
| $existingProperty->is_final = $promotedProperty->is_final; | ||
| } | ||
|
|
||
| // Recurse into nullable type | ||
| if ($typeNode instanceof \PhpParser\Node\NullableType) { | ||
| return self::containsPHP82PlusType($typeNode->type); | ||
| if ($existingProperty->access_set === '' && $promotedProperty->access_set !== '') { | ||
| $existingProperty->access_set = $promotedProperty->access_set; | ||
| } | ||
|
|
||
| return false; | ||
| if ($existingProperty->hooks === [] && $promotedProperty->hooks !== []) { | ||
| $existingProperty->hooks = $promotedProperty->hooks; | ||
| } | ||
|
|
||
| if ($existingProperty->attributes === [] && $promotedProperty->attributes !== []) { | ||
| $existingProperty->attributes = $promotedProperty->attributes; | ||
| } | ||
|
Comment on lines
+512
to
+530
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When merging promoted property data, the if ($existingProperty->is_readonly === null && $promotedProperty->is_readonly !== null) {
$existingProperty->is_readonly = $promotedProperty->is_readonly;
}
if ($existingProperty->is_final === null && $promotedProperty->is_final !== null) {
$existingProperty->is_final = $promotedProperty->is_final;
}
if ($existingProperty->access_set === '' && $promotedProperty->access_set !== '') {
$existingProperty->access_set = $promotedProperty->access_set;
}
if ($existingProperty->hooks === [] && $promotedProperty->hooks !== []) {
$existingProperty->hooks = $promotedProperty->hooks;
}
if ($existingProperty->attributes === [] && $promotedProperty->attributes !== []) {
$existingProperty->attributes = $promotedProperty->attributes;
} |
||
|
|
||
| if ($parameter->default !== null && $promotedProperty->typeFromDefaultValue !== null) { | ||
| $existingProperty->defaultValue = $promotedProperty->defaultValue; | ||
| $existingProperty->typeFromDefaultValue = $promotedProperty->typeFromDefaultValue; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a helper method to check for the
finalmodifier flag, as properties (including promoted ones) can now be marked as final in PHP 8.4.