Skip to content

Commit

Permalink
[DeadCode] Handle native function call not exists in RemoveUnusedPriv…
Browse files Browse the repository at this point in the history
…atePropertyRector (#72)

* [DeadCode] Handle native function call not exists in RemoveUnusedPrivatePropertyRector

* phpstan

* [ci-review] Rector Rectify

Co-authored-by: kaizen-ci <info@kaizen-ci.org>
  • Loading branch information
samsonasik and kaizen-ci committed May 19, 2021
1 parent cc546e6 commit ce7bdaa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/ReadWrite/Guard/VariableToConstantGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ private function resolveFunctionReferencePositions(FunctionReflection $functionR

// this is needed, as native function reflection does not have access to referenced parameters
if ($functionReflection instanceof NativeFunctionReflection) {
$nativeFunctionReflection = new ReflectionFunction($functionReflection->getName());
$functionName = $functionReflection->getName();
if (! function_exists($functionName)) {
return [];
}

$nativeFunctionReflection = new ReflectionFunction($functionName);
} else {
$nativeFunctionReflection = $this->privatesAccessor->getPrivateProperty($functionReflection, 'reflection');
}
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@ parameters:

-
message: '#Function "function_exists\(\)" cannot be used/left in the code#'
path: src/functions/node_helper.php
paths:
- src/functions/node_helper.php
- packages/ReadWrite/Guard/VariableToConstantGuard.php

# upgrade to PHP 7.4 wip
- '#This property type might be inlined to PHP\. Do you have confidence it is correct\? Put it here#'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Rector\Tests\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector\Fixture;

class NativeFunctionCallNotExists
{
private $resultID;
private $rowOffset;
public function getFieldCount(): int
{
return sqlsrv_num_fields($this->resultID);
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector\Fixture;

class NativeFunctionCallNotExists
{
private $resultID;
public function getFieldCount(): int
{
return sqlsrv_num_fields($this->resultID);
}
}

?>

0 comments on commit ce7bdaa

Please sign in to comment.