From 9b0e270cd4e97d3aa7fa2d74b8df744629482eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20HULARD?= Date: Fri, 2 Feb 2018 12:28:40 +0100 Subject: [PATCH] fix(php-cs-fixer) Method signature changed. Attached to #51. The PhpCsFixer\AbstractLinesBeforeNamespaceFixer::fixLinesBeforeNamespace signature as changed in PHP-CS-Fixer v2.8.1 : * The offending commit : FriendsOfPHP/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... --- .../Fixer/NoBlankLinesBeforeEntity.php | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Resource/PHPCSFixer/Fixer/NoBlankLinesBeforeEntity.php b/Resource/PHPCSFixer/Fixer/NoBlankLinesBeforeEntity.php index 4bc04cacd..e94299487 100644 --- a/Resource/PHPCSFixer/Fixer/NoBlankLinesBeforeEntity.php +++ b/Resource/PHPCSFixer/Fixer/NoBlankLinesBeforeEntity.php @@ -39,6 +39,7 @@ use PhpCsFixer\AbstractLinesBeforeNamespaceFixer; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\Tokenizer\Tokens; +use PhpCsFixer\Console\Application; use SplFileInfo; /** @@ -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) { @@ -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); + } } }