bug: Fix FullyQualifiedStrictTypesFixer common prefix bug#6898
bug: Fix FullyQualifiedStrictTypesFixer common prefix bug#6898Wirone merged 2 commits intoPHP-CS-Fixer:masterfrom
Conversation
|
@edsrzf thank you very much for providing fix! Can I ask you to split provided changes into separate commits: one with failing test case, and other one with the fix? That would be easier to verify it locally (by checking out one commit behind). Generally it's good approach to prepare PR with failing test, run the workflow, see it fails and then providing fix, but this unfortunately does not work good for first time contributors, when you need to wait for the approval.. Unfortunately I don't have enough rights to approve workflow, so we need to wait for someone else to trigger it. |
1945231 to
e2f6244
Compare
The fully_qualified_strict_types rule had a bug when a class in the root
namespace was used, and that class had a common prefix with the current
namespace.
For example, this input:
```php
<?php
namespace Foo;
function foo(\FooBar $v): \FooBar {}
```
would be transformed into:
```php
<?php
namespace Foo;
function foo(ar $v): ar {}
```
This change fixes the bug.
|
I've re-pushed my branch with separate commits. This would be useful information to have in |
|
@edsrzf in the end all commits from PR are squashed so in the main branch every commit is passing (in theory 😅). Splitting commits makes sense only for bug fixes - first we make reproduction case and confirm it fails in this particular scenario, then we fix it 🙂. |
Wirone
left a comment
There was a problem hiding this comment.
Before fix:
vendor/bin/phpunit tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php
PHPUnit 9.6.6 by Sebastian Bergmann and contributors.
Testing PhpCsFixer\Tests\Fixer\Import\FullyQualifiedStrictTypesFixerTest
.......F................................. 41 / 41 (100%)
Time: 00:00.086, Memory: 24.00 MB
There was 1 failure:
1) PhpCsFixer\Tests\Fixer\Import\FullyQualifiedStrictTypesFixerTest::testNewLogic with data set "common prefix" ('<?php namespace Foo; function...Bar {}', null)
Code build on expected code must not change.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'<?php namespace Foo; function foo(\FooBar $v): \FooBar {}'
+'<?php namespace Foo; function foo(ar $v): ar {}'
LGTM 👍
|
Thank you, @edsrzf 🍻 |
The
fully_qualified_strict_typesrule had a bug when a class in the root namespace was used, and that class had a common prefix with the current namespace.For example, this input:
would be transformed into:
This change fixes the bug.