Skip to content

Commit d512cda

Browse files
[framework] messenger: prevent errors when MESSENGER_TRANSPORT_DSN is empty (#3114)
2 parents 98fa4ce + 3753901 commit d512cda

File tree

9 files changed

+147
-3
lines changed

9 files changed

+147
-3
lines changed

src/CsFixer/Phpdoc/AbstractMissingAnnotationsFixer.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpCsFixer\DocBlock\DocBlock;
99
use PhpCsFixer\Fixer\FixerInterface;
1010
use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer;
11+
use PhpCsFixer\Tokenizer\CT;
1112
use PhpCsFixer\Tokenizer\Token;
1213
use PhpCsFixer\Tokenizer\Tokens;
1314
use PhpCsFixer\WhitespacesFixerConfig;
@@ -166,13 +167,39 @@ protected function getDocIndex(Tokens $tokens, int $index): int
166167
{
167168
do {
168169
$index = $tokens->getPrevNonWhitespace($index);
170+
171+
$index = $this->skipAttributes($tokens, $index);
169172
} while ($tokens[$index]->isGivenKind(
170-
[T_STATIC, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_COMMENT],
173+
[T_STATIC, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_COMMENT, T_ATTRIBUTE, CT::T_ATTRIBUTE_CLOSE],
171174
));
172175

173176
return $index;
174177
}
175178

179+
/**
180+
* @param \PhpCsFixer\Tokenizer\Tokens $tokens
181+
* @param int $index
182+
* @return int
183+
*/
184+
public function skipAttributes(Tokens $tokens, int $index): int
185+
{
186+
if ($tokens[$index]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
187+
$depth = 1;
188+
189+
while ($depth > 0 && $index > 0) {
190+
$index--;
191+
192+
if ($tokens[$index]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
193+
$depth++;
194+
} elseif ($tokens[$index]->isGivenKind(T_ATTRIBUTE)) {
195+
$depth--;
196+
}
197+
}
198+
}
199+
200+
return $index;
201+
}
202+
176203
/**
177204
* @param \PhpCsFixer\DocBlock\Line[] $newLines
178205
* @param string $indent
@@ -191,7 +218,6 @@ protected function createDocContentFromLinesAndIndent(array $newLines, string $i
191218
/**
192219
* @param \PhpCsFixer\Tokenizer\Token $docToken
193220
* @param \PhpCsFixer\DocBlock\Line[] $newLines
194-
* @param int|null $offset
195221
* @return string
196222
*/
197223
protected function createDocContentFromDocTokenAndNewLines(Token $docToken, array $newLines): string
@@ -218,7 +244,11 @@ protected function getNewDocIndex(Tokens $tokens, int $index): int
218244
{
219245
for ($i = $index; $i > 0; --$i) {
220246
if ($this->isWhitespaceWithNewline($tokens, $i)) {
221-
return $i + 1;
247+
if (!$tokens[$i - 1]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
248+
return $i + 1;
249+
}
250+
251+
return $this->skipAttributes($tokens, $i - 1);
222252
}
223253
}
224254

tests/Unit/CsFixer/Phpdoc/MissingParamAnnotationsFixer/MissingParamAnnotationsFixerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function getTestingFiles(): iterable
5555

5656
yield [__DIR__ . '/fixed/fixed6.php', __DIR__ . '/wrong/wrong6.php'];
5757

58+
yield [__DIR__ . '/fixed/fixed7.php', __DIR__ . '/wrong/wrong7.php'];
59+
5860
yield [__DIR__ . '/correct/correct.php'];
5961
}
6062
}

tests/Unit/CsFixer/Phpdoc/MissingParamAnnotationsFixer/correct/correct.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace Shopsys\ProductFeed\ZboziBundle\Form;
44

5+
use Override;
6+
use ReturnTypeWillChange;
57
use Shopsys\FormTypesBundle\MultidomainType;
68
use Shopsys\FormTypesBundle\YesNoType;
9+
use Shopsys\FrameworkBundle\Component\EntityLog\Attribute\EntityLogIdentify;
710
use Shopsys\FrameworkBundle\Component\Money\Money;
811
use Shopsys\FrameworkBundle\Form\Constraints\MoneyRange;
912
use Symfony\Component\Form\AbstractType;
@@ -28,10 +31,19 @@ public function __construct(TranslatorInterface $translator)
2831
$this->translator = $translator;
2932
}
3033

34+
/**
35+
* @param string $bar
36+
*/
37+
#[EntityLogIdentify(isLocalized: true)]
38+
public function foo(string $bar): void
39+
{
40+
}
41+
3142
/**
3243
* @param \Symfony\Component\Form\FormBuilderInterface $builder
3344
* @param array $options
3445
*/
46+
#[Override]
3547
public function buildForm(FormBuilderInterface $builder, array $options)
3648
{
3749
$builder
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\CodingStandards\Tests;
6+
7+
class SomeParentClassWithAttribute
8+
{
9+
/**
10+
* @param string $bar
11+
*/
12+
public function foo(string $bar): void
13+
{
14+
}
15+
}
16+
17+
class SomeClass extends SomeParentClassWithAttribute
18+
{
19+
/**
20+
* @param string $bar
21+
*/
22+
#[\Override]
23+
public function foo(string $bar): void
24+
{
25+
}
26+
27+
/**
28+
* @param string $foo
29+
* @param string $bar
30+
*/
31+
#[\ReturnTypeWillChange]
32+
public function bar(string $foo, string $bar): void
33+
{
34+
}
35+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\CodingStandards\Tests;
6+
7+
class SomeParentClassWithAttribute
8+
{
9+
/**
10+
* @param string $bar
11+
*/
12+
public function foo(string $bar): void
13+
{
14+
}
15+
}
16+
17+
class SomeClass extends SomeParentClassWithAttribute
18+
{
19+
#[\Override]
20+
public function foo(string $bar): void
21+
{
22+
}
23+
24+
/**
25+
* @param string $bar
26+
*/
27+
#[\ReturnTypeWillChange]
28+
public function bar(string $foo, string $bar): void
29+
{
30+
}
31+
}

tests/Unit/CsFixer/Phpdoc/MissingReturnAnnotationFixer/MissingReturnAnnotationFixerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function getTestingFiles(): iterable
4747

4848
yield [__DIR__ . '/fixed/fixed2.php', __DIR__ . '/wrong/wrong2.php'];
4949

50+
yield [__DIR__ . '/fixed/fixed3.php', __DIR__ . '/wrong/wrong3.php'];
51+
5052
yield [__DIR__ . '/correct/correct.php'];
5153
}
5254
}

tests/Unit/CsFixer/Phpdoc/MissingReturnAnnotationFixer/correct/correct.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ public static function isDebug(string $environment): bool
1818
{
1919
return $environment === self::DEVELOPMENT;
2020
}
21+
22+
/**
23+
* @return bool
24+
*/
25+
#[\ReturnTypeWillChange]
26+
public function foo(): bool
27+
{
28+
return true;
29+
}
2130
}
2231

2332

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
class SomeClass
4+
{
5+
/**
6+
* @return int
7+
*/
8+
#[\ReturnTypeWillChange]
9+
public function function1(): int
10+
{
11+
return 0;
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class SomeClass
4+
{
5+
#[\ReturnTypeWillChange]
6+
public function function1(): int
7+
{
8+
return 0;
9+
}
10+
}

0 commit comments

Comments
 (0)