Skip to content

Commit

Permalink
fix: phpspec void remove linebreak (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller authored Apr 26, 2021
1 parent 7461e49 commit fc4d3ea
Show file tree
Hide file tree
Showing 39 changed files with 257 additions and 616 deletions.
13 changes: 11 additions & 2 deletions src/PedroTroller/CS/Fixer/PhpspecFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
use PhpCsFixer\Tokenizer\Token;
Expand Down Expand Up @@ -99,7 +100,10 @@ public function getDocumentation()
*/
public function getPriority()
{
return Priority::after(VisibilityRequiredFixer::class);
return Priority::after(
VisibilityRequiredFixer::class,
VoidReturnFixer::class
);
}

/**
Expand Down Expand Up @@ -223,7 +227,12 @@ private function removeReturn(SplFileInfo $file, Tokens $tokens): void
}

$tokens->clearRange($closeBraceIndex + 1, $openCurlyBracket - 1);
$tokens->ensureWhitespaceAtIndex($openCurlyBracket, 0, "\n".$this->analyze($tokens)->getLineIndentation($openBraceIndex));

if ($tokens[$closeBraceIndex - 1]->isWhitespace() && false !== strpos($tokens[$closeBraceIndex - 1]->getContent(), "\n")) {
$tokens->ensureWhitespaceAtIndex($openCurlyBracket, 0, ' ');
} else {
$tokens->ensureWhitespaceAtIndex($openCurlyBracket, 0, "\n".$this->analyze($tokens)->getLineIndentation($openBraceIndex));
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static function runUseCases(): void
continue;
}

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

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

$fixer->fix(new SplFileInfo(__FILE__), $tokens);
foreach ($fixers as $fixer) {
$fixer->fix(new SplFileInfo(__FILE__), $tokens);
}

if ($usecase->getExpectation() !== $tokens->generateCode()) {
throw new Exception($differ->diff($usecase->getExpectation(), $tokens->generateCode()));
Expand Down
19 changes: 5 additions & 14 deletions tests/UseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,13 @@
interface UseCase
{
/**
* @return FixerInterface
* @return iterable<FixerInterface>
*/
public function getFixer();
public function getFixers(): iterable;

/**
* @return string
*/
public function getRawScript();
public function getRawScript(): string;

/**
* @return string
*/
public function getExpectation();
public function getExpectation(): string;

/**
* @return int
*/
public function getMinSupportedPhpVersion();
public function getMinSupportedPhpVersion(): int;
}
10 changes: 5 additions & 5 deletions tests/UseCase/Behat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

final class Behat implements UseCase
{
public function getFixer()
public function getFixers(): iterable
{
return new OrderBehatStepsFixer();
yield new OrderBehatStepsFixer();
}

public function getRawScript()
public function getRawScript(): string
{
return <<<'CONTEXT'
<?php
Expand Down Expand Up @@ -129,7 +129,7 @@ public function iAmAnnon()
CONTEXT;
}

public function getExpectation()
public function getExpectation(): string
{
return <<<'CONTEXT'
<?php
Expand Down Expand Up @@ -227,7 +227,7 @@ public function doSomething()
CONTEXT;
}

public function getMinSupportedPhpVersion()
public function getMinSupportedPhpVersion(): int
{
return 0;
}
Expand Down
22 changes: 5 additions & 17 deletions tests/UseCase/CommentLineToPhpdocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

final class CommentLineToPhpdocBlock implements UseCase
{
/**
* {@inheritdoc}
*/
public function getFixer()
public function getFixers(): iterable
{
return new CommentLineToPhpdocBlockFixer();
yield new CommentLineToPhpdocBlockFixer();
}

/**
* {@inheritdoc}
*/
public function getRawScript()
public function getRawScript(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -79,10 +73,7 @@ public function update(array $data)
PHP;
}

/**
* {@inheritdoc}
*/
public function getExpectation()
public function getExpectation(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -150,10 +141,7 @@ public function update(array $data)
PHP;
}

/**
* {@inheritdoc}
*/
public function getMinSupportedPhpVersion()
public function getMinSupportedPhpVersion(): int
{
return 0;
}
Expand Down
22 changes: 5 additions & 17 deletions tests/UseCase/DoctrineMigrations/UselessComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

final class UselessComments implements UseCase
{
/**
* {@inheritdoc}
*/
public function getFixer()
public function getFixers(): iterable
{
return new DoctrineMigrationsFixer();
yield new DoctrineMigrationsFixer();
}

/**
* {@inheritdoc}
*/
public function getRawScript()
public function getRawScript(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -61,10 +55,7 @@ public function down(Schema $schema): void
PHP;
}

/**
* {@inheritdoc}
*/
public function getExpectation()
public function getExpectation(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -100,10 +91,7 @@ public function down(Schema $schema): void
PHP;
}

/**
* {@inheritdoc}
*/
public function getMinSupportedPhpVersion()
public function getMinSupportedPhpVersion(): int
{
return 70100;
}
Expand Down
22 changes: 5 additions & 17 deletions tests/UseCase/DoctrineMigrations/UselessGetDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

final class UselessGetDescription implements UseCase
{
/**
* {@inheritdoc}
*/
public function getFixer()
public function getFixers(): iterable
{
return new DoctrineMigrationsFixer();
yield new DoctrineMigrationsFixer();
}

/**
* {@inheritdoc}
*/
public function getRawScript()
public function getRawScript(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -56,10 +50,7 @@ public function down(Schema $schema): void
PHP;
}

/**
* {@inheritdoc}
*/
public function getExpectation()
public function getExpectation(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -91,10 +82,7 @@ public function down(Schema $schema): void
PHP;
}

/**
* {@inheritdoc}
*/
public function getMinSupportedPhpVersion()
public function getMinSupportedPhpVersion(): int
{
return 70100;
}
Expand Down
22 changes: 5 additions & 17 deletions tests/UseCase/ExceptionsPunctuation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

final class ExceptionsPunctuation implements UseCase
{
/**
* {@inheritdoc}
*/
public function getFixer()
public function getFixers(): iterable
{
return new ExceptionsPunctuationFixer();
yield new ExceptionsPunctuationFixer();
}

/**
* {@inheritdoc}
*/
public function getRawScript()
public function getRawScript(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -52,10 +46,7 @@ public function fun4($data)
PHP;
}

/**
* {@inheritdoc}
*/
public function getExpectation()
public function getExpectation(): string
{
return <<<'PHP'
<?php
Expand Down Expand Up @@ -87,10 +78,7 @@ public function fun4($data)
PHP;
}

/**
* {@inheritdoc}
*/
public function getMinSupportedPhpVersion()
public function getMinSupportedPhpVersion(): int
{
return 0;
}
Expand Down
22 changes: 5 additions & 17 deletions tests/UseCase/ForbiddenFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

final class ForbiddenFunctions implements UseCase
{
/**
* {@inheritdoc}
*/
public function getFixer()
public function getFixers(): iterable
{
$fixer = new ForbiddenFunctionsFixer();

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

return $fixer;
yield $fixer;
}

/**
* {@inheritdoc}
*/
public function getRawScript()
public function getRawScript(): string
{
return <<<'PHP'
<?php
Expand All @@ -54,10 +48,7 @@ public function dump($data)
PHP;
}

/**
* {@inheritdoc}
*/
public function getExpectation()
public function getExpectation(): string
{
return <<<'PHP'
<?php
Expand All @@ -84,10 +75,7 @@ public function dump($data)
PHP;
}

/**
* {@inheritdoc}
*/
public function getMinSupportedPhpVersion()
public function getMinSupportedPhpVersion(): int
{
return 0;
}
Expand Down
Loading

0 comments on commit fc4d3ea

Please sign in to comment.