Skip to content

Commit

Permalink
Handle variable copy for self detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Feb 24, 2024
1 parent 7929829 commit f02541c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ jobs:

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --no-progress --prefer-${{ matrix.setup }} --prefer-dist --no-progress --ignore-platform-req=php+
run: composer update --no-progress --prefer-${{ matrix.setup }} --prefer-dist --no-progress${{ matrix.php >= 8 && ' --ignore-platform-req=php+' || '' }}

- name: Install test dependencies
if: steps.composer-test-cache.outputs.cache-hit != 'true'
run: cd src/test && composer update --no-progress --prefer-dist --prefer-stable --ignore-platform-req=php+
run: cd src/test && composer update --no-progress --prefer-dist --prefer-stable${{ matrix.php >= 8 && ' --ignore-platform-req=php+' || '' }}

- name: Fix PHP compatibility
run: php src/test/php/fix-php-compatibility.php
Expand Down
10 changes: 9 additions & 1 deletion src/main/php/PHPMD/Rule/UnusedPrivateMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ protected function calculateInstanceOfTheCurrentClass(ClassNode $class, ASTNode
$parent = $occurrence->getParent();

if ($parent->isInstanceOf('AssignmentExpression')) {
$lastWriting = $this->getChildIfExist($parent, 1);
$assigned = $this->getChildIfExist($parent, 0);

if ($assigned && $assigned->getImage() === $name) {
$lastWriting = $this->getChildIfExist($parent, 1);
}
}
}

Expand All @@ -307,6 +311,10 @@ protected function calculateInstanceOfTheCurrentClass(ClassNode $class, ASTNode
&& ($value->isInstanceOf('SelfReference') || $value->isInstanceOf('StaticReference'));
}

if ($lastWriting->isInstanceOf('Variable') && $lastWriting->getImage() !== $name) {
return $this->isInstanceOfTheCurrentClass($class, $lastWriting);
}

return false;
}

Expand Down
5 changes: 1 addition & 4 deletions src/test/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"phpunit/phpunit": "5.7.27"
},
"config": {
"process-timeout": 900,
"platform": {
"php": "7.2.0"
}
"process-timeout": 900
}
}
2 changes: 1 addition & 1 deletion src/test/php/PHPMD/Cache/Model/ResultCacheStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ResultCacheStateTest extends TestCase
/** @var ResultCacheState */
private $state;

protected function setUp(): void
protected function setUp()
{
$this->key = new ResultCacheKey(true, 'baseline', array(), array(), 123);
$this->state = new ResultCacheState($this->key, array());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function foo2()

}

public function bar(Bar|(static&StuffInterface)|Biz $obj)
public function bar(Bar|(Biz&StuffInterface)|self $obj)
{
$obj->foo1();

Expand Down

0 comments on commit f02541c

Please sign in to comment.