Skip to content

Commit

Permalink
fix: FullyQualifiedStrictTypesFixer - do not modify statements with…
Browse files Browse the repository at this point in the history
… property fetch and `::` (#7749)
  • Loading branch information
kubawerlos committed Jan 16, 2024
1 parent 64d0009 commit e3afa32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Fixer/Import/FullyQualifiedStrictTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ private function fixPrevName(Tokens $tokens, int $index, array $uses, string $na

while (true) {
$index = $tokens->getPrevMeaningfulToken($index);
if ($tokens[$index]->isObjectOperator()) {
break;
}

if ($tokens[$index]->equalsAny([[T_STRING], [T_NS_SEPARATOR]])) {
$typeStartIndex = $index;
Expand Down
24 changes: 24 additions & 0 deletions tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,21 @@ class Cl {}
new R\T();
EOD,
];

yield 'do not fix property named the same as class' => [
<<<'EOD'
<?php
namespace Foo;
use Bar\Service;
class Baz {
public function getValue()
{
return $this->service::getValueFromService();
}
}
EOD,
];
}

/**
Expand Down Expand Up @@ -2057,6 +2072,15 @@ public function foo(): void {}
',
['import_symbols' => true],
];

yield 'do not fix property named the same as class' => [
<<<'EOD'
<?php
namespace Foo;
use Bar\Baz;
echo $x?->baz::CONSTANT_1;
EOD,
];
}

/**
Expand Down

0 comments on commit e3afa32

Please sign in to comment.