Skip to content

Commit

Permalink
Update dependency nikic/php-parser to ^5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Dec 30, 2024
1 parent 9a9ca56 commit 9e682f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 43 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"php": "~8.2.0 || ~8.3.2 || ~8.4.1",
"ext-json": "*",
"jetbrains/phpstorm-stubs": "2024.3",
"nikic/php-parser": "^5.3.1"
"nikic/php-parser": "^5.4.0"
},
"authors": [
{
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@
<code><![CDATA[getEndLine]]></code>
<code><![CDATA[getStartLine]]></code>
<code><![CDATA[getStmts]]></code>
<code><![CDATA[getStmts]]></code>
<code><![CDATA[isAbstract]]></code>
<code><![CDATA[isFinal]]></code>
<code><![CDATA[isPrivate]]></code>
<code><![CDATA[isPrivateSet]]></code>
<code><![CDATA[isProtected]]></code>
Expand Down
44 changes: 10 additions & 34 deletions src/Reflection/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Closure;
use Error;
use OutOfBoundsException;
use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\Stmt\Property as PropertyNode;
use PhpParser\NodeTraverser;
Expand Down Expand Up @@ -35,7 +34,6 @@

use function array_map;
use function assert;
use function count;
use function func_num_args;
use function is_object;
use function sprintf;
Expand Down Expand Up @@ -675,8 +673,8 @@ private function computeModifiers(PropertyNode $node): int
$modifiers += $node->isProtected() ? CoreReflectionProperty::IS_PROTECTED : 0;
$modifiers += $node->isProtectedSet() ? ReflectionPropertyAdapter::IS_PROTECTED_SET_COMPATIBILITY : 0;
$modifiers += $node->isPublic() ? CoreReflectionProperty::IS_PUBLIC : 0;
$modifiers += ($node->flags & ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY) === ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY ? ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY : 0;
$modifiers += ($node->flags & Modifiers::ABSTRACT) === Modifiers::ABSTRACT ? ReflectionPropertyAdapter::IS_ABSTRACT_COMPATIBILITY : 0;
$modifiers += $node->isFinal() ? ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY : 0;
$modifiers += $node->isAbstract() ? ReflectionPropertyAdapter::IS_ABSTRACT_COMPATIBILITY : 0;

/** @phpstan-ignore return.type */
return $modifiers;
Expand All @@ -699,51 +697,29 @@ private function computeImmediateVirtual(PropertyNode $node): bool
}
}

if ($setHook !== null && ! $this->computeImmediateVirtualBasedOnSetHook($setHook)) {
if ($setHook !== null && ! $this->computeImmediateVirtualBasedOnHook($setHook)) {
return false;
}

if ($getHook === null) {
return true;
}

return $this->computeImmediateVirtualBasedOnGetHook($getHook);
return $this->computeImmediateVirtualBasedOnHook($getHook);
}

private function computeImmediateVirtualBasedOnGetHook(Node\PropertyHook $getHook): bool
private function computeImmediateVirtualBasedOnHook(Node\PropertyHook $hook): bool
{
$getHookBody = $getHook->getStmts();
$hookBody = $hook->getStmts();

// Abstract property or property in interface
if ($getHookBody === null) {
if ($hookBody === null) {
return true;
}

return ! $this->isHookUsingThisProperty($getHook);
}

private function computeImmediateVirtualBasedOnSetHook(Node\PropertyHook $setHook): bool
{
$setHookBody = $setHook->getStmts();

// Abstract property or property in interface
if ($setHookBody === null) {
return true;
}

// Short syntax
if (count($setHookBody) === 1 && $setHookBody[0] instanceof Node\Stmt\Return_) {
return false;
}

return ! $this->isHookUsingThisProperty($setHook);
}

private function isHookUsingThisProperty(Node\PropertyHook $hook): bool
{
$visitor = new FindingVisitor(static fn (Node $node): bool => $node instanceof Node\Expr\PropertyFetch);
$traverser = new NodeTraverser($visitor);
$traverser->traverse([$hook]);
$traverser->traverse($hookBody);

foreach ($visitor->getFoundNodes() as $propertyFetchNode) {
assert($propertyFetchNode instanceof Node\Expr\PropertyFetch);
Expand All @@ -754,11 +730,11 @@ private function isHookUsingThisProperty(Node\PropertyHook $hook): bool
&& $propertyFetchNode->name instanceof Node\Identifier
&& $propertyFetchNode->name->name === $this->name
) {
return true;
return false;
}
}

return false;
return true;
}

/** @return array{get?: ReflectionMethod, set?: ReflectionMethod} */
Expand Down

0 comments on commit 9e682f8

Please sign in to comment.