Skip to content

Commit

Permalink
Merge pull request phpspec#628 from jrfnl/feature/fix-reflection-docb…
Browse files Browse the repository at this point in the history
…lock-deprecation

MagicCallPatch: prevent deprecation notice
  • Loading branch information
stof authored Aug 21, 2024
2 parents 196305b + d9d1858 commit d1235b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/Prophecy/Doubler/ClassPatch/MagicCallPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ public function apply(ClassNode $node)

// only magic methods can have a contract that needs to be enforced
if (in_array($methodName, self::MAGIC_METHODS_WITH_ARGUMENTS)) {
foreach($tag->getArguments() as $argument) {
$argumentNode = new ArgumentNode($argument['name']);
$methodNode->addArgument($argumentNode);
if (method_exists($tag, 'getParameters')) {
// Reflection Docblock 5.4.0+.
foreach($tag->getParameters() as $argument) {
$argumentNode = new ArgumentNode($argument->getName());
$methodNode->addArgument($argumentNode);
}
} else {
// Reflection Docblock < 5.4.0.
foreach($tag->getArguments() as $argument) {
$argumentNode = new ArgumentNode($argument['name']);
$methodNode->addArgument($argumentNode);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion tests/Doubler/ClassPatch/MagicCallPatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ public function it_supports_arguments_for_magic_methods()

$classNode = $this->applyPatchTo($class);

$this->assertEquals([new ArgumentNode('data')], $classNode->getMethod('__unserialize')->getArguments());
$method = $classNode->getMethod('__unserialize');
if (method_exists($method, 'getParameters')) {
// Reflection Docblock 5.4.0+.
$args = $method->getParameters();
} else {
// Reflection Docblock < 5.4.0.
$args = $method->getArguments();
}

$this->assertEquals([new ArgumentNode('data')], $args);
}

private function applyPatchTo(\ReflectionClass $class): ClassNode
Expand Down

0 comments on commit d1235b2

Please sign in to comment.