Skip to content

Commit a8604fe

Browse files
committed
bug #4630 FullyQualifiedStrictTypesFixer - Ignore partial class names which look like FQCNs (localheinz, SpacePossum)
This PR was squashed before being merged into the 2.15 branch (closes #4630). Discussion ---------- FullyQualifiedStrictTypesFixer - Ignore partial class names which look like FQCNs This PR * [x] adds a failing test case * [x] ignores types when they are not references relative to the root namespace Commits ------- 0785928 FullyQualifiedStrictTypesFixer - Ignore partial class names which look like FQCNs
2 parents 6593e66 + 0785928 commit a8604fe

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/Fixer/Import/FullyQualifiedStrictTypesFixer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ private function detectAndReplaceTypeWithShortType(
152152
}
153153

154154
$typeName = $type->getName();
155+
156+
if (0 !== strpos($typeName, '\\')) {
157+
return;
158+
}
159+
155160
$shortType = (new TypeShortNameResolver())->resolve($tokens, $typeName);
156161
if ($shortType === $typeName) {
157162
return;

tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@ class SomeClass
111111
public function doSomething(\Foo\Bar\SomeClass $foo, \Foo\Bar\Buz $buz, \Foo\Bar\Zoof\Buz $barbuz): \Foo\Bar\Baz
112112
{
113113
}
114+
}',
115+
],
116+
'Partial class name looks like FQCN' => [
117+
'<?php
118+
119+
namespace One;
120+
121+
use Two\Three;
122+
123+
class Two
124+
{
125+
/**
126+
* Note that for this example, the following classes exist:
127+
*
128+
* - One\Two
129+
* - One\Two\Three
130+
* - Two\Three\Four
131+
*/
132+
public function three(Three\Four $four): Two\Three
133+
{
134+
}
114135
}',
115136
],
116137
'Test multi namespace fixes' => [
@@ -247,6 +268,28 @@ public function doSomething(\Foo\Bar\SomeClass $foo, \Foo\Bar\Buz $buz, \Foo\Bar
247268
}
248269
}',
249270
],
271+
'Partial class name looks like FQCN' => [
272+
'<?php
273+
274+
namespace One;
275+
276+
use Two\Three;
277+
278+
class Two
279+
{
280+
/**
281+
* Note that for this example, the following classes exist:
282+
*
283+
* - One\Two
284+
* - One\Two\Three
285+
* - Two\Three
286+
*/
287+
public function three(Two\Three $three, Three $other)
288+
{
289+
}
290+
}',
291+
],
292+
250293
'Test multi namespace fixes' => [
251294
'<?php
252295
namespace Foo\Other {
@@ -407,6 +450,27 @@ class SomeClass
407450
public function doSomething(\Foo\Bar\SomeClass $foo, \Foo\Bar\Buz $buz, ?\Foo\Bar\Zoof\Buz $barbuz): ?\Foo\Bar\Baz
408451
{
409452
}
453+
}',
454+
],
455+
'Partial class name looks like FQCN' => [
456+
'<?php
457+
458+
namespace One;
459+
460+
use Two\Three;
461+
462+
class Two
463+
{
464+
/**
465+
* Note that for this example, the following classes exist:
466+
*
467+
* - One\Two
468+
* - One\Two\Three
469+
* - Two\Three\Four
470+
*/
471+
public function three(Three\Four $four): ?Two\Three
472+
{
473+
}
410474
}',
411475
],
412476
];

0 commit comments

Comments
 (0)