diff --git a/phpcs-ruleset.xml b/phpcs-ruleset.xml index 398389ac..8d730a68 100644 --- a/phpcs-ruleset.xml +++ b/phpcs-ruleset.xml @@ -39,7 +39,7 @@ - + diff --git a/src/Manager.php b/src/Manager.php index beb3b923..081cef43 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -65,6 +65,7 @@ public function run(Settings $settings = null) $parallelLint = new ParallelLint($phpExecutable, $settings->parallelJobs); $parallelLint->setAspTagsEnabled($settings->aspTags); $parallelLint->setShortTagEnabled($settings->shortTag); + $parallelLint->setShowDeprecated($settings->showDeprecated); $parallelLint->setProcessCallback(function ($status, $file) use ($output) { if ($status === ParallelLint::STATUS_OK) { diff --git a/src/ParallelLint.php b/src/ParallelLint.php index 1811dbbc..ec88c7c3 100644 --- a/src/ParallelLint.php +++ b/src/ParallelLint.php @@ -56,6 +56,9 @@ class ParallelLint /** @var callable */ private $processCallback; + /** @var bool */ + private $showDeprecated = false; + public function __construct(PhpExecutable $phpExecutable, $parallelJobs = 10) { $this->phpExecutable = $phpExecutable; @@ -95,7 +98,8 @@ public function lint(array $files) $this->phpExecutable, $file, $this->aspTagsEnabled, - $this->shortTagEnabled + $this->shortTagEnabled, + $this->showDeprecated ); } } @@ -115,14 +119,15 @@ public function lint(array $files) $skippedFiles[] = $file; $processCallback(self::STATUS_SKIP, $file); + } else if ($process->containsError()) { + $checkedFiles[] = $file; + $errors[] = new SyntaxError($file, $process->getSyntaxError()); + $processCallback(self::STATUS_ERROR, $file); + } else if ($process->isSuccess()) { $checkedFiles[] = $file; $processCallback(self::STATUS_OK, $file); - } else if ($process->hasSyntaxError()) { - $checkedFiles[] = $file; - $errors[] = new SyntaxError($file, $process->getSyntaxError()); - $processCallback(self::STATUS_ERROR, $file); } else { $errors[] = new Error($file, $process->getOutput()); @@ -153,7 +158,7 @@ public function lint(array $files) $checkedFiles[] = $file; $processCallback(self::STATUS_OK, $file); - } else if ($process->hasSyntaxError()) { + } else if ($process->containsError()) { $checkedFiles[] = $file; $errors[] = new SyntaxError($file, $process->getSyntaxError()); $processCallback(self::STATUS_ERROR, $file); @@ -264,4 +269,23 @@ public function setShortTagEnabled($shortTagEnabled) return $this; } + + /** + * @return boolean + */ + public function isShowDeprecated() + { + return $this->showDeprecated; + } + + /** + * @param $showDeprecated + * @return ParallelLint + */ + public function setShowDeprecated($showDeprecated) + { + $this->showDeprecated = $showDeprecated; + + return $this; + } } diff --git a/src/Process/LintProcess.php b/src/Process/LintProcess.php index defe0c50..bffdb922 100644 --- a/src/Process/LintProcess.php +++ b/src/Process/LintProcess.php @@ -7,14 +7,21 @@ class LintProcess extends PhpProcess { const FATAL_ERROR = 'Fatal error'; const PARSE_ERROR = 'Parse error'; + const DEPRECATED_ERROR = 'Deprecated:'; + + /** + * @var bool + */ + private $showDeprecatedErrors; /** * @param PhpExecutable $phpExecutable * @param string $fileToCheck Path to file to check * @param bool $aspTags * @param bool $shortTag + * @param bool $deprecated */ - public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags = false, $shortTag = false) + public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags = false, $shortTag = false, $deprecated = false) { if (empty($fileToCheck)) { throw new \InvalidArgumentException("File to check must be set."); @@ -29,13 +36,14 @@ public function __construct(PhpExecutable $phpExecutable, $fileToCheck, $aspTags escapeshellarg($fileToCheck), ); + $this->showDeprecatedErrors = $deprecated; parent::__construct($phpExecutable, $parameters); } /** * @return bool */ - public function hasSyntaxError() + public function containsError() { return $this->containsParserOrFatalError($this->getOutput()); } @@ -46,8 +54,7 @@ public function hasSyntaxError() */ public function getSyntaxError() { - if ($this->hasSyntaxError()) { - // Look for fatal errors first + if ($this->containsError()) { foreach (explode("\n", $this->getOutput()) as $line) { if ($this->containsFatalError($line)) { return $line; @@ -107,6 +114,17 @@ private function containsParserError($string) */ private function containsFatalError($string) { - return strpos($string, self::FATAL_ERROR) !== false; + return strpos($string, self::FATAL_ERROR) !== false || + strpos($string, self::PARSE_ERROR) !== false || + $this->containsDeprecatedError($string); + } + + private function containsDeprecatedError($string) + { + if ($this->showDeprecatedErrors === false) { + return false; + } + + return strpos($string, self::DEPRECATED_ERROR) !== false; } } diff --git a/src/Settings.php b/src/Settings.php index 3b2fb58f..35da14a9 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -127,6 +127,11 @@ class Settings */ public $ignoreFails = false; + /** + * @var bool + */ + public $showDeprecated = false; + /** * @param array $paths */ @@ -212,6 +217,10 @@ public static function parseArguments(array $arguments) $settings->ignoreFails = true; break; + case '--show-deprecated': + $settings->showDeprecated = true; + break; + default: throw new InvalidArgumentException($argument); } diff --git a/tests/ParallelLint.lint.phpt b/tests/ParallelLint.lint.phpt index 2aecb127..b42a0444 100644 --- a/tests/ParallelLint.lint.phpt +++ b/tests/ParallelLint.lint.phpt @@ -92,6 +92,28 @@ class ParallelLintLintTest extends Tester\TestCase Assert::equal(1, count($result->getErrors())); } + public function testDeprecated() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array(__DIR__ . '/examples/example-05/Foo.php')); + Assert::equal(1, $result->getCheckedFilesCount()); + Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); + Assert::false($result->hasSyntaxError()); + Assert::equal(0, count($result->getErrors())); + + if (PHP_VERSION_ID < 70000) { + Tester\Environment::skip('test for php version > 7.0'); + } + + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $parallelLint->setShowDeprecated(true); + $result = $parallelLint->lint(array(__DIR__ . '/examples/example-05/Foo.php')); + Assert::equal(1, $result->getCheckedFilesCount()); + Assert::equal(1, $result->getFilesWithSyntaxErrorCount()); + Assert::true($result->hasSyntaxError()); + Assert::equal(1, count($result->getErrors())); + } + public function testValidAndInvalidFiles() { $parallelLint = new ParallelLint($this->getPhpExecutable()); diff --git a/tests/Settings.parseArguments.phpt b/tests/Settings.parseArguments.phpt index 20ca998b..7746bef0 100644 --- a/tests/Settings.parseArguments.phpt +++ b/tests/Settings.parseArguments.phpt @@ -58,6 +58,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase $expectedSettings->colors = Settings::DISABLED; $expectedSettings->showProgress = true; $expectedSettings->format = Settings::FORMAT_TEXT; + $expectedSettings->deprecated = false; Assert::equal($expectedSettings->phpExecutable, $settings->phpExecutable); Assert::equal($expectedSettings->shortTag, $settings->shortTag); @@ -69,6 +70,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase Assert::equal($expectedSettings->colors, $settings->colors); Assert::equal($expectedSettings->showProgress, $settings->showProgress); Assert::equal($expectedSettings->format, $settings->format); + Assert::equal($expectedSettings->showDeprecated, $settings->showDeprecated); } public function testColorsForced() diff --git a/tests/examples/example-05/Foo.php b/tests/examples/example-05/Foo.php new file mode 100644 index 00000000..fcdbf3b1 --- /dev/null +++ b/tests/examples/example-05/Foo.php @@ -0,0 +1,15 @@ +bar = $bar; + } +}