Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
fix(php-cs-fixer) Method signature changed.
Browse files Browse the repository at this point in the history
Attached to #51.

The PhpCsFixer\AbstractLinesBeforeNamespaceFixer::fixLinesBeforeNamespace signature as changed in PHP-CS-Fixer v2.8.1 :

* The offending commit : PHP-CS-Fixer/PHP-CS-Fixer@d3a7101#diff-41cf271d3466dbb2548c606fee86f147L30

Since Hoa rely on the host installed php-cs-fixer binary, we have an edge case to check here...
  • Loading branch information
shulard committed Feb 2, 2018
1 parent e95b4da commit 9b0e270
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Resource/PHPCSFixer/Fixer/NoBlankLinesBeforeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use PhpCsFixer\AbstractLinesBeforeNamespaceFixer;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Console\Application;
use SplFileInfo;

/**
Expand All @@ -51,6 +52,21 @@
*/
class NoBlankLinesBeforeEntity extends AbstractLinesBeforeNamespaceFixer
{
/**
* Are we using php-cs-fixer > 2.8.0
* @var boolean
*/
private $v28 = false;

public function __construct()
{
parent::__construct();

if (version_compare(Application::VERSION, '2.8.0') > 0) {
$this->v28 = true;
}
}

protected function applyfix(SplFileInfo $file, Tokens $tokens)
{
foreach ($tokens as $index => $token) {
Expand All @@ -64,7 +80,15 @@ protected function applyfix(SplFileInfo $file, Tokens $tokens)
false
);
$firstSignificantIndex = $tokens->getNextNonWhitespace($docCommentIndex);
$this->fixLinesBeforeNamespace($tokens, $firstSignificantIndex, 1);

//The fixLinesBeforeNamespace has changed signature after the
//php-cs-fixer v2.8.1 release.
//@see https://github.com/FriendsOfPHP/PHP-CS-Fixer/commit/d3a71014777b2d5f35da75944c1ad2a6e983aed4#diff-41cf271d3466dbb2548c606fee86f147
if (true === $this->v28) {
$this->fixLinesBeforeNamespace($tokens, $firstSignificantIndex, 0, 1);
} else {
$this->fixLinesBeforeNamespace($tokens, $firstSignificantIndex, 1);
}
}
}

Expand Down

0 comments on commit 9b0e270

Please sign in to comment.