Skip to content

Commit fc4d3ea

Browse files
authored
fix: phpspec void remove linebreak (#140)
1 parent 7461e49 commit fc4d3ea

39 files changed

+257
-616
lines changed

src/PedroTroller/CS/Fixer/PhpspecFixer.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
88
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
9+
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
910
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
1011
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
1112
use PhpCsFixer\Tokenizer\Token;
@@ -99,7 +100,10 @@ public function getDocumentation()
99100
*/
100101
public function getPriority()
101102
{
102-
return Priority::after(VisibilityRequiredFixer::class);
103+
return Priority::after(
104+
VisibilityRequiredFixer::class,
105+
VoidReturnFixer::class
106+
);
103107
}
104108

105109
/**
@@ -223,7 +227,12 @@ private function removeReturn(SplFileInfo $file, Tokens $tokens): void
223227
}
224228

225229
$tokens->clearRange($closeBraceIndex + 1, $openCurlyBracket - 1);
226-
$tokens->ensureWhitespaceAtIndex($openCurlyBracket, 0, "\n".$this->analyze($tokens)->getLineIndentation($openBraceIndex));
230+
231+
if ($tokens[$closeBraceIndex - 1]->isWhitespace() && false !== strpos($tokens[$closeBraceIndex - 1]->getContent(), "\n")) {
232+
$tokens->ensureWhitespaceAtIndex($openCurlyBracket, 0, ' ');
233+
} else {
234+
$tokens->ensureWhitespaceAtIndex($openCurlyBracket, 0, "\n".$this->analyze($tokens)->getLineIndentation($openBraceIndex));
235+
}
227236
}
228237
}
229238

tests/Runner.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static function runUseCases(): void
8080
continue;
8181
}
8282

83-
$fixer = $usecase->getFixer();
83+
$fixers = $usecase->getFixers();
8484
$tokens = Tokens::fromCode($usecase->getRawScript());
8585

8686
$differ = new Differ();
@@ -90,7 +90,9 @@ private static function runUseCases(): void
9090
echo "#######################################################################################\n";
9191
echo "\n";
9292

93-
$fixer->fix(new SplFileInfo(__FILE__), $tokens);
93+
foreach ($fixers as $fixer) {
94+
$fixer->fix(new SplFileInfo(__FILE__), $tokens);
95+
}
9496

9597
if ($usecase->getExpectation() !== $tokens->generateCode()) {
9698
throw new Exception($differ->diff($usecase->getExpectation(), $tokens->generateCode()));

tests/UseCase.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,13 @@
99
interface UseCase
1010
{
1111
/**
12-
* @return FixerInterface
12+
* @return iterable<FixerInterface>
1313
*/
14-
public function getFixer();
14+
public function getFixers(): iterable;
1515

16-
/**
17-
* @return string
18-
*/
19-
public function getRawScript();
16+
public function getRawScript(): string;
2017

21-
/**
22-
* @return string
23-
*/
24-
public function getExpectation();
18+
public function getExpectation(): string;
2519

26-
/**
27-
* @return int
28-
*/
29-
public function getMinSupportedPhpVersion();
20+
public function getMinSupportedPhpVersion(): int;
3021
}

tests/UseCase/Behat.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
final class Behat implements UseCase
1111
{
12-
public function getFixer()
12+
public function getFixers(): iterable
1313
{
14-
return new OrderBehatStepsFixer();
14+
yield new OrderBehatStepsFixer();
1515
}
1616

17-
public function getRawScript()
17+
public function getRawScript(): string
1818
{
1919
return <<<'CONTEXT'
2020
<?php
@@ -129,7 +129,7 @@ public function iAmAnnon()
129129
CONTEXT;
130130
}
131131

132-
public function getExpectation()
132+
public function getExpectation(): string
133133
{
134134
return <<<'CONTEXT'
135135
<?php
@@ -227,7 +227,7 @@ public function doSomething()
227227
CONTEXT;
228228
}
229229

230-
public function getMinSupportedPhpVersion()
230+
public function getMinSupportedPhpVersion(): int
231231
{
232232
return 0;
233233
}

tests/UseCase/CommentLineToPhpdocBlock.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
final class CommentLineToPhpdocBlock implements UseCase
1111
{
12-
/**
13-
* {@inheritdoc}
14-
*/
15-
public function getFixer()
12+
public function getFixers(): iterable
1613
{
17-
return new CommentLineToPhpdocBlockFixer();
14+
yield new CommentLineToPhpdocBlockFixer();
1815
}
1916

20-
/**
21-
* {@inheritdoc}
22-
*/
23-
public function getRawScript()
17+
public function getRawScript(): string
2418
{
2519
return <<<'PHP'
2620
<?php
@@ -79,10 +73,7 @@ public function update(array $data)
7973
PHP;
8074
}
8175

82-
/**
83-
* {@inheritdoc}
84-
*/
85-
public function getExpectation()
76+
public function getExpectation(): string
8677
{
8778
return <<<'PHP'
8879
<?php
@@ -150,10 +141,7 @@ public function update(array $data)
150141
PHP;
151142
}
152143

153-
/**
154-
* {@inheritdoc}
155-
*/
156-
public function getMinSupportedPhpVersion()
144+
public function getMinSupportedPhpVersion(): int
157145
{
158146
return 0;
159147
}

tests/UseCase/DoctrineMigrations/UselessComments.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
final class UselessComments implements UseCase
1111
{
12-
/**
13-
* {@inheritdoc}
14-
*/
15-
public function getFixer()
12+
public function getFixers(): iterable
1613
{
17-
return new DoctrineMigrationsFixer();
14+
yield new DoctrineMigrationsFixer();
1815
}
1916

20-
/**
21-
* {@inheritdoc}
22-
*/
23-
public function getRawScript()
17+
public function getRawScript(): string
2418
{
2519
return <<<'PHP'
2620
<?php
@@ -61,10 +55,7 @@ public function down(Schema $schema): void
6155
PHP;
6256
}
6357

64-
/**
65-
* {@inheritdoc}
66-
*/
67-
public function getExpectation()
58+
public function getExpectation(): string
6859
{
6960
return <<<'PHP'
7061
<?php
@@ -100,10 +91,7 @@ public function down(Schema $schema): void
10091
PHP;
10192
}
10293

103-
/**
104-
* {@inheritdoc}
105-
*/
106-
public function getMinSupportedPhpVersion()
94+
public function getMinSupportedPhpVersion(): int
10795
{
10896
return 70100;
10997
}

tests/UseCase/DoctrineMigrations/UselessGetDescription.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
final class UselessGetDescription implements UseCase
1111
{
12-
/**
13-
* {@inheritdoc}
14-
*/
15-
public function getFixer()
12+
public function getFixers(): iterable
1613
{
17-
return new DoctrineMigrationsFixer();
14+
yield new DoctrineMigrationsFixer();
1815
}
1916

20-
/**
21-
* {@inheritdoc}
22-
*/
23-
public function getRawScript()
17+
public function getRawScript(): string
2418
{
2519
return <<<'PHP'
2620
<?php
@@ -56,10 +50,7 @@ public function down(Schema $schema): void
5650
PHP;
5751
}
5852

59-
/**
60-
* {@inheritdoc}
61-
*/
62-
public function getExpectation()
53+
public function getExpectation(): string
6354
{
6455
return <<<'PHP'
6556
<?php
@@ -91,10 +82,7 @@ public function down(Schema $schema): void
9182
PHP;
9283
}
9384

94-
/**
95-
* {@inheritdoc}
96-
*/
97-
public function getMinSupportedPhpVersion()
85+
public function getMinSupportedPhpVersion(): int
9886
{
9987
return 70100;
10088
}

tests/UseCase/ExceptionsPunctuation.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99

1010
final class ExceptionsPunctuation implements UseCase
1111
{
12-
/**
13-
* {@inheritdoc}
14-
*/
15-
public function getFixer()
12+
public function getFixers(): iterable
1613
{
17-
return new ExceptionsPunctuationFixer();
14+
yield new ExceptionsPunctuationFixer();
1815
}
1916

20-
/**
21-
* {@inheritdoc}
22-
*/
23-
public function getRawScript()
17+
public function getRawScript(): string
2418
{
2519
return <<<'PHP'
2620
<?php
@@ -52,10 +46,7 @@ public function fun4($data)
5246
PHP;
5347
}
5448

55-
/**
56-
* {@inheritdoc}
57-
*/
58-
public function getExpectation()
49+
public function getExpectation(): string
5950
{
6051
return <<<'PHP'
6152
<?php
@@ -87,10 +78,7 @@ public function fun4($data)
8778
PHP;
8879
}
8980

90-
/**
91-
* {@inheritdoc}
92-
*/
93-
public function getMinSupportedPhpVersion()
81+
public function getMinSupportedPhpVersion(): int
9482
{
9583
return 0;
9684
}

tests/UseCase/ForbiddenFunctions.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99

1010
final class ForbiddenFunctions implements UseCase
1111
{
12-
/**
13-
* {@inheritdoc}
14-
*/
15-
public function getFixer()
12+
public function getFixers(): iterable
1613
{
1714
$fixer = new ForbiddenFunctionsFixer();
1815

@@ -21,13 +18,10 @@ public function getFixer()
2118
'functions' => ['var_dump', 'dump'],
2219
]);
2320

24-
return $fixer;
21+
yield $fixer;
2522
}
2623

27-
/**
28-
* {@inheritdoc}
29-
*/
30-
public function getRawScript()
24+
public function getRawScript(): string
3125
{
3226
return <<<'PHP'
3327
<?php
@@ -54,10 +48,7 @@ public function dump($data)
5448
PHP;
5549
}
5650

57-
/**
58-
* {@inheritdoc}
59-
*/
60-
public function getExpectation()
51+
public function getExpectation(): string
6152
{
6253
return <<<'PHP'
6354
<?php
@@ -84,10 +75,7 @@ public function dump($data)
8475
PHP;
8576
}
8677

87-
/**
88-
* {@inheritdoc}
89-
*/
90-
public function getMinSupportedPhpVersion()
78+
public function getMinSupportedPhpVersion(): int
9179
{
9280
return 0;
9381
}

0 commit comments

Comments
 (0)