Skip to content

Commit ab76c08

Browse files
committed
bug #5137 DoctrineAnnotationSpacesFixer - fix for typed properties (kubawerlos)
This PR was squashed before being merged into the 2.15 branch (closes #5137). Discussion ---------- DoctrineAnnotationSpacesFixer - fix for typed properties Fixes #5135 Pinging @enumag for review (as reporter of bug). Commits ------- b58ee56 DoctrineAnnotationSpacesFixer - fix for typed properties
2 parents 9749943 + b58ee56 commit ab76c08

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/AbstractDoctrineAnnotationFixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
1717
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
1818
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
19+
use PhpCsFixer\Tokenizer\CT;
1920
use PhpCsFixer\Tokenizer\Token as PhpToken;
2021
use PhpCsFixer\Tokenizer\Tokens as PhpTokens;
2122
use PhpCsFixer\Tokenizer\TokensAnalyzer;
@@ -212,7 +213,7 @@ private function nextElementAcceptsDoctrineAnnotations(PhpTokens $tokens, $index
212213
return true;
213214
}
214215

215-
while ($tokens[$index]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT])) {
216+
while ($tokens[$index]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_NS_SEPARATOR, T_STRING, CT::T_NULLABLE_TYPE])) {
216217
$index = $tokens->getNextMeaningfulToken($index);
217218
}
218219

tests/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixerTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,4 +2198,42 @@ public function provideFixWithoutSpaceAfterArrayAssignmentColonOnlyCases()
21982198
*/'],
21992199
]);
22002200
}
2201+
2202+
/**
2203+
* @param string $element
2204+
*
2205+
* @requires PHP 7.4
2206+
* @dataProvider provideElementDiscoveringCases
2207+
*/
2208+
public function testElementDiscovering($element)
2209+
{
2210+
$this->doTest(
2211+
sprintf('<?php
2212+
class Foo
2213+
{
2214+
/**
2215+
* @Foo(foo="foo")
2216+
*/
2217+
%s
2218+
}
2219+
', $element),
2220+
sprintf('<?php
2221+
class Foo
2222+
{
2223+
/**
2224+
* @Foo(foo = "foo")
2225+
*/
2226+
%s
2227+
}
2228+
', $element)
2229+
);
2230+
}
2231+
2232+
public static function provideElementDiscoveringCases()
2233+
{
2234+
yield ['private $foo;'];
2235+
yield ['private string $foo;'];
2236+
yield ['private Foo\Bar $foo;'];
2237+
yield ['private ?Foo\Bar $foo;'];
2238+
}
22012239
}

0 commit comments

Comments
 (0)