diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c15e5..3df611d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,39 +8,70 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [Unreleased]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.3.0...HEAD +## [1.3.1] - 2021-08-13 + +### Added + +- Extend by the Code Climate output format [#50] from [@lukas9393]. + +### Fixed + +- PHP 8.1: silence the deprecation notices about missing return types [#64] from [@jrfnl]. + +### Internal + +- Reformat changelog to use reflinks in changelog entries [#58] from [@glensc]. + +[1.3.1]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.3.0...1.3.1 + +[#50]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/50 +[#58]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/58 +[#64]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/64 + ## [1.3.0] - 2021-04-07 ### Added -- Allow for multi-part file extensions to be passed using -e (like `-e php,php.dist`) from [@jrfnl](https://github.com/jrfnl). -- Added syntax error callback [#30](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/30) from [@arxeiss](https://github.com/arxeiss). -- Ignore PHP startup errors [#34](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/34) from [@jrfnl](https://github.com/jrfnl). -- Restore php 5.3 support [#51](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/51) from [@glensc](https://github.com/glensc). +- Allow for multi-part file extensions to be passed using -e (like `-e php,php.dist`) from [@jrfnl]. +- Added syntax error callback [#30] from [@arxeiss]. +- Ignore PHP startup errors [#34] from [@jrfnl]. +- Restore php 5.3 support [#51] from [@glensc]. ### Fixed -- Determine skip lint process failure by status code instead of stderr content [#48](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/48) from [@jankonas](https://github.com/jankonas). +- Determine skip lint process failure by status code instead of stderr content [#48] from [@jankonas]. ### Changed -- Improve wording in the readme [#52](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/52) from [@glensc](https://github.com/glensc). +- Improve wording in the readme [#52] from [@glensc]. ### Internal -- Normalized composer.json from [@OndraM](https://github.com/OndraM). -- Updated PHPCS dependency from [@jrfnl](https://github.com/jrfnl). -- Cleaned coding style from [@jrfnl](https://github.com/jrfnl). -- Provide one true way to run the test suite [#37](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/37) from [@mfn](https://github.com/mfn). -- Travis: add build against PHP 8.0 and fix failing test [#41](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/41) from [@jrfnl](https://github.com/jrfnl). -- GitHub Actions for testing, and automatic phar creation [#46](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/46) from [@roelofr](https://github.com/roelofr). -- Add .github folder to .gitattributes export-ignore [#54](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/54) from [@glensc](https://github.com/glensc). -- Suggest to curl composer install via HTTPS [#53](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/53) from [@reedy](https://github.com/reedy). -- GH Actions: allow for manually triggering a workflow [#55](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/55) from [@jrfnl](https://github.com/jrfnl). -- GH Actions: fix phar creation [#55](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/55) from [@jrfnl](https://github.com/jrfnl). -- GH Actions: run the tests against all supported PHP versions [#55](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/55) from [@jrfnl](https://github.com/jrfnl). -- GH Actions: report CS violations in the PR [#55](https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/55) from [@jrfnl](https://github.com/jrfnl). +- Normalized composer.json from [@OndraM]. +- Updated PHPCS dependency from [@jrfnl]. +- Cleaned coding style from [@jrfnl]. +- Provide one true way to run the test suite [#37] from [@mfn]. +- Travis: add build against PHP 8.0 and fix failing test [#41] from [@jrfnl]. +- GitHub Actions for testing, and automatic phar creation [#46] from [@roelofr]. +- Add .github folder to .gitattributes export-ignore [#54] from [@glensc]. +- Suggest to curl composer install via HTTPS [#53] from [@reedy]. +- GH Actions: allow for manually triggering a workflow [#55] from [@jrfnl]. +- GH Actions: fix phar creation [#55] from [@jrfnl]. +- GH Actions: run the tests against all supported PHP versions [#55] from [@jrfnl]. +- GH Actions: report CS violations in the PR [#55] from [@jrfnl]. [1.3.0]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.2.0...v1.3.0 +[#30]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/30 +[#34]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/34 +[#37]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/37 +[#41]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/41 +[#46]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/46 +[#48]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/48 +[#51]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/51 +[#52]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/52 +[#53]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/53 +[#54]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/54 +[#55]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/pull/55 ## [1.2.0] - 2020-04-04 @@ -50,17 +81,31 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed -- Fixed vendor location for running from other folder from [@Erkens](https://github.com/Erkens). +- Fixed vendor location for running from other folder from [@Erkens]. ### Internal -- Added a .gitattributes file from [@jrfnl](https://github.com/jrfnl), thanks for issue to [@ondrejmirtes](https://github.com/ondrejmirtes). -- Fixed incorrect unit tests from [@jrfnl](https://github.com/jrfnl). -- Fixed minor grammatical errors from [@jrfnl](https://github.com/jrfnl). -- Added Travis: test against nightly (= PHP 8) from [@jrfnl](https://github.com/jrfnl). -- Travis: removed sudo from [@jrfnl](https://github.com/jrfnl). +- Added a .gitattributes file from [@jrfnl], thanks for issue to [@ondrejmirtes]. +- Fixed incorrect unit tests from [@jrfnl]. +- Fixed minor grammatical errors from [@jrfnl]. +- Added Travis: test against nightly (= PHP 8) from [@jrfnl]. +- Travis: removed sudo from [@jrfnl]. - Added info about installing like not a dependency. - Cleaned readme - new organization from previous package. -- Added checklist for new version from [@szepeviktor](https://github.com/szepeviktor). +- Added checklist for new version from [@szepeviktor]. [1.2.0]: https://github.com/php-parallel-lint/PHP-Parallel-Lint/compare/v1.1.0...v1.2.0 + +[@Erkens]: https://github.com/Erkens +[@OndraM]: https://github.com/OndraM +[@arxeiss]: https://github.com/arxeiss +[@glensc]: https://github.com/glensc +[@jankonas]: https://github.com/jankonas +[@jrfnl]: https://github.com/jrfnl +[@mfn]: https://github.com/mfn +[@ondrejmirtes]: https://github.com/ondrejmirtes +[@reedy]: https://github.com/reedy +[@roelofr]: https://github.com/roelofr +[@szepeviktor]: https://github.com/szepeviktor +[@lukas9393]: https://github.com/lukas9393 + diff --git a/README.md b/README.md index e5c762f..eb546e9 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ It is strongly recommended for existing users of the (unmaintained) - `--no-progress` Disable progress in console output. - `--checkstyle` Output results as Checkstyle XML. - `--json` Output results as JSON string (requires PHP 5.4). +- `--gitlab` Output results for the GitLab Code Quality widget (requires PHP 5.4), see more in [Code Quality](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html) documentation. - `--blame` Try to show git blame for row with error. - `--git ` Path to Git executable to show blame message (default: 'git'). - `--stdin` Load files and folder to test from standard input. diff --git a/composer.json b/composer.json index ce7ed04..55d5812 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "nette/tester": "^1.3 || ^2.0", "php-parallel-lint/php-console-highlighter": "~0.3", - "squizlabs/php_codesniffer": "^3.5" + "squizlabs/php_codesniffer": "^3.6" }, "suggest": { "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" diff --git a/src/Application.php b/src/Application.php index d38e42d..4b4017e 100644 --- a/src/Application.php +++ b/src/Application.php @@ -4,7 +4,7 @@ class Application { - const VERSION = '1.3.0'; + const VERSION = '1.3.1'; // Return codes const SUCCESS = 0, @@ -87,6 +87,7 @@ private function showOptions() --no-colors Disable colors in console output. --no-progress Disable progress in console output. --json Output results as JSON string. + --gitlab Output results for the GitLab Code Quality Widget. --checkstyle Output results as Checkstyle XML. --blame Try to show git blame for row with error. --git Path to Git executable to show blame message (default: 'git'). diff --git a/src/Error.php b/src/Error.php index 9041ab1..0c9f65f 100644 --- a/src/Error.php +++ b/src/Error.php @@ -1,6 +1,8 @@ json_encode, * which is a value of any type other than a resource. */ + #[ReturnTypeWillChange] public function jsonSerialize() { return array( @@ -87,6 +90,7 @@ class Blame implements \JsonSerializable * @return mixed data which can be serialized by json_encode, * which is a value of any type other than a resource. */ + #[ReturnTypeWillChange] function jsonSerialize() { return array( diff --git a/src/Manager.php b/src/Manager.php index 63091b1..84b7434 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -4,6 +4,7 @@ use JakubOnderka\PhpParallelLint\Contracts\SyntaxErrorCallback; use JakubOnderka\PhpParallelLint\Process\GitBlameProcess; use JakubOnderka\PhpParallelLint\Process\PhpExecutable; +use ReturnTypeWillChange; class Manager { @@ -82,6 +83,8 @@ protected function getDefaultOutput(Settings $settings) switch ($settings->format) { case Settings::FORMAT_JSON: return new JsonOutput($writer); + case Settings::FORMAT_GITLAB: + return new GitLabOutput($writer); case Settings::FORMAT_CHECKSTYLE: return new CheckstyleOutput($writer); } @@ -224,6 +227,7 @@ public function __construct(\RecursiveDirectoryIterator $iterator, array $exclud * @link http://php.net/manual/en/filteriterator.accept.php * @return bool true if the current element is acceptable, otherwise false. */ + #[ReturnTypeWillChange] public function accept() { $current = $this->current()->getPathname(); @@ -243,6 +247,7 @@ public function accept() * @link http://php.net/manual/en/recursivefilteriterator.haschildren.php * @return bool true if the inner iterator has children, otherwise false */ + #[ReturnTypeWillChange] public function hasChildren() { return $this->iterator->hasChildren(); @@ -255,6 +260,7 @@ public function hasChildren() * @link http://php.net/manual/en/recursivefilteriterator.getchildren.php * @return \RecursiveFilterIterator containing the inner iterator's children. */ + #[ReturnTypeWillChange] public function getChildren() { return new self($this->iterator->getChildren(), $this->excluded); diff --git a/src/Output.php b/src/Output.php index c51d11b..974dde8 100644 --- a/src/Output.php +++ b/src/Output.php @@ -85,6 +85,81 @@ public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ign } } +class GitLabOutput implements Output +{ + /** @var IWriter */ + protected $writer; + + /** + * @param IWriter $writer + */ + public function __construct(IWriter $writer) + { + $this->writer = $writer; + } + + public function ok() + { + + } + + public function skip() + { + + } + + public function error() + { + + } + + public function fail() + { + + } + + public function setTotalFileCount($count) + { + + } + + public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null) + { + + } + + public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails) + { + $errors = array(); + foreach ($result->getErrors() as $error) { + $message = $error->getMessage(); + $line = 1; + if ($error instanceof SyntaxError) { + $line = $error->getLine(); + } + $filePath = $error->getFilePath(); + $result = array( + 'type' => 'issue', + 'check_name' => 'Parse error', + 'description' => $message, + 'categories' => 'Style', + 'fingerprint' => md5($filePath . $message . $line), + 'severity' => 'minor', + 'location' => array( + 'path' => $filePath, + 'lines' => array( + 'begin' => $line, + ), + ), + ); + array_push($errors, $result); + } + + $string = json_encode($errors) . PHP_EOL; + $this->writer->write($string); + } +} + class TextOutput implements Output { const TYPE_DEFAULT = 'default', diff --git a/src/Result.php b/src/Result.php index 6004374..9f6a368 100644 --- a/src/Result.php +++ b/src/Result.php @@ -1,6 +1,8 @@ json_encode, * which is a value of any type other than a resource. */ + #[ReturnTypeWillChange] function jsonSerialize() { return array( diff --git a/src/Settings.php b/src/Settings.php index 3e03a71..40cb8b1 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -13,6 +13,7 @@ class Settings const FORMAT_TEXT = 'text'; const FORMAT_JSON = 'json'; + const FORMAT_GITLAB = 'gitlab'; const FORMAT_CHECKSTYLE = 'checkstyle'; /** @@ -179,6 +180,10 @@ public static function parseArguments(array $arguments) $settings->format = self::FORMAT_JSON; break; + case '--gitlab': + $settings->format = self::FORMAT_GITLAB; + break; + case '--checkstyle': $settings->format = self::FORMAT_CHECKSTYLE; break; diff --git a/src/exceptions.php b/src/exceptions.php index 3893b83..b96f28a 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -1,8 +1,11 @@ writeResult($result, new ErrorFormatter(), true); + + $result = (array) json_decode($writer->getLogs()); + + for ($i = 0; $i < count($result) && $i < count($errors); $i++) { + $message = $errors[$i]->getMessage(); + $filePath = $errors[$i]->getFilePath(); + $line = 1; + if ($errors[$i] instanceof SyntaxError) { + $line = $errors[$i]->getLine(); + } + Assert::equal($result[$i]->type, 'issue'); + Assert::equal($result[$i]->check_name, 'Parse error'); + Assert::equal($result[$i]->categories, 'Style'); + Assert::equal($result[$i]->severity, 'minor'); + Assert::equal($result[$i]->description, $message); + Assert::equal($result[$i]->fingerprint, md5($filePath . $message . $line)); + Assert::equal($result[$i]->location->path, $filePath); + Assert::equal($result[$i]->location->lines->begin, $line); + } + } + + public function getGitLabOutputData() + { + return array( + array( + 'errors' => array() + ), + array( + 'errors' => array( + new SyntaxError('foo/bar.php', "Parse error: syntax error, unexpected in foo/bar.php on line 52") + ) + ), + array( + 'errors' => array( + new JakubOnderka\PhpParallelLint\Error('foo/bar.php', "PHP Parse error: syntax error, unexpected ';'") + ) + ), + array( + 'errors' => array( + new SyntaxError('foo/bar.php', "Parse error: syntax error, unexpected in foo/bar.php on line 52"), + new JakubOnderka\PhpParallelLint\Error('foo/bar.php', "PHP Parse error: syntax error, unexpected ';'") + ) + ), + ); + } +} + +class TestWriter implements IWriter +{ + /** @var string */ + protected $logs = ""; + + /** + * @param string $string + */ + public function write($string) + { + $this->logs .= $string; + } + + public function getLogs() + { + return $this->logs; + } +} + +$testCase = new OutputTest; +$testCase->run(); diff --git a/tests/Settings.parseArguments.phpt b/tests/Settings.parseArguments.phpt index 0a83673..a669195 100644 --- a/tests/Settings.parseArguments.phpt +++ b/tests/Settings.parseArguments.phpt @@ -103,6 +103,14 @@ class SettingsParseArgumentsTest extends Tester\TestCase Assert::equal(Settings::FORMAT_JSON, $settings->format); } + public function testGitLabOutput() + { + $commandLine = './parallel-lint --gitlab .'; + $argv = explode(" ", $commandLine); + $settings = Settings::parseArguments($argv); + Assert::equal(Settings::FORMAT_GITLAB, $settings->format); + } + public function testCheckstyleOutput() { $commandLine = './parallel-lint --checkstyle .';