Skip to content

Commit

Permalink
[Php80] Handle crash on extends \mysqli on AddParamBasedOnParentClass…
Browse files Browse the repository at this point in the history
…MethodRector (#3009)

* [Php80] Handle crash on extends \mysqli on AddParamBasedOnParentClassMethodRector

* Fixed 🎉
  • Loading branch information
samsonasik committed Oct 23, 2022
1 parent 64b241f commit 0f1af3c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture;

// when there is no \mysqli class, it may pull from scoper phar file
final class ExtendsMysqli extends \mysqli
{
public function query($query) {
//Code
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture;

// when there is no \mysqli class, it may pull from scoper phar file
final class ExtendsMysqli extends \mysqli
{
public function query($query,
#[\JetBrains\PhpStorm\Internal\PhpStormStubsElementAvailable(from: '7.1')]
int $result_mode = \MYSQLI_STORE_RESULT) {
//Code
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Php80\Rector\ClassMethod;

use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Expr;
Expand Down Expand Up @@ -222,9 +223,13 @@ function (Node $subNode) use ($parentClassMethodParam): bool {
$parentClassMethodParam->byRef,
$parentClassMethodParam->variadic,
[],
$parentClassMethodParam->flags,
$parentClassMethodParam->attrGroups
$parentClassMethodParam->flags
);

if ($parentClassMethodParam->attrGroups !== []) {
$attrGroupsAsComment = $this->nodePrinter->print($parentClassMethodParam->attrGroups);
$node->params[$key]->setAttribute(AttributeKey::COMMENTS, [new Comment($attrGroupsAsComment)]);
}
}

return $node;
Expand Down

0 comments on commit 0f1af3c

Please sign in to comment.