From 26fca2a1c213418ef8cf653f77be7429f3b85751 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Fri, 6 Dec 2019 10:05:09 -0500 Subject: [PATCH] Add linting check to CI to help catch version-incompatible code --- .travis.yml | 1 + Jenkinsfile | 3 +++ RoboFile.php | 34 +++++++++++++++++----------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e71487a..f757ac7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ php: script: - mkdir -p build/logs + - vendor/bin/robo lint - phpdbg -qrr -- vendor/bin/phpunit -c build after_script: diff --git a/Jenkinsfile b/Jenkinsfile index 132d26e7..16633b6e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,7 @@ pipeline { sh 'curl -sS https://getcomposer.org/installer | php' sh 'rm -f composer.lock' sh 'php composer.phar install --ignore-platform-reqs' + sh 'php vendor/bin/robo lint' sh 'phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never' } } @@ -28,6 +29,7 @@ pipeline { sh 'curl -sS https://getcomposer.org/installer | php' sh 'rm -f composer.lock' sh 'php composer.phar install --ignore-platform-reqs' + sh 'php vendor/bin/robo lint' sh 'phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never' } } @@ -43,6 +45,7 @@ pipeline { sh 'curl -sS https://getcomposer.org/installer | php' sh 'rm -f composer.lock' sh 'php composer.phar install --ignore-platform-reqs' + sh 'php vendor/bin/robo lint' sh 'phpdbg -qrr -- ./vendor/bin/phpunit --coverage-text --colors=never' } } diff --git a/RoboFile.php b/RoboFile.php index 310dcb0d..b7b50e3d 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -54,7 +54,7 @@ class RoboFile extends Tasks { /** * Do static analysis tasks */ - public function analyze() + public function analyze(): void { $this->prepare(); $this->lint(); @@ -67,7 +67,7 @@ class RoboFile extends Tasks { /** * Run all tests, generate coverage, generate docs, generate code statistics */ - public function build() + public function build(): void { $this->analyze(); $this->coverage(); @@ -77,19 +77,19 @@ class RoboFile extends Tasks { /** * Cleanup temporary files */ - public function clean() + public function clean(): void { $cleanFiles = [ 'build/humbug.json', 'build/humbug-log.txt', ]; - array_map(function ($file) { + array_map(static function ($file) { @unlink($file); }, $cleanFiles); // So the task doesn't complain, // make any 'missing' dirs to cleanup - array_map(function ($dir) { + array_map(static function ($dir) { if ( ! is_dir($dir)) { `mkdir -p {$dir}`; @@ -103,7 +103,7 @@ class RoboFile extends Tasks { /** * Run unit tests and generate coverage reports */ - public function coverage() + public function coverage(): void { $this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']); } @@ -111,7 +111,7 @@ class RoboFile extends Tasks { /** * Generate documentation with phpdox */ - public function docs() + public function docs(): void { $cmd_parts = [ 'vendor/bin/phpdox', @@ -122,7 +122,7 @@ class RoboFile extends Tasks { /** * Verify that source files are valid */ - public function lint() + public function lint(): void { $files = $this->getAllSourceFiles(); @@ -139,7 +139,7 @@ class RoboFile extends Tasks { * * @param bool $report - if true, generates reports instead of direct output */ - public function phpcs($report = FALSE) + public function phpcs($report = FALSE): void { $report_cmd_parts = [ 'vendor/bin/phpcs', @@ -162,7 +162,7 @@ class RoboFile extends Tasks { * * @param bool $report - if true, generates reports instead of direct output */ - public function phploc($report = FALSE) + public function phploc($report = FALSE): void { // Command for generating reports $report_cmd_parts = [ @@ -190,7 +190,7 @@ class RoboFile extends Tasks { /** * Create temporary directories */ - public function prepare() + public function prepare(): void { array_map([$this, '_mkdir'], $this->taskDirs); } @@ -198,7 +198,7 @@ class RoboFile extends Tasks { /** * Lint php files and run unit tests */ - public function test() + public function test(): void { $this->lint(); @@ -208,7 +208,7 @@ class RoboFile extends Tasks { /** * Create pdepend reports */ - protected function dependencyReport() + protected function dependencyReport(): void { $cmd_parts = [ 'vendor/bin/pdepend', @@ -225,7 +225,7 @@ class RoboFile extends Tasks { * * @return array */ - protected function getAllSourceFiles() + protected function getAllSourceFiles(): array { $files = array_merge( glob_recursive('build/*.php'), @@ -246,7 +246,7 @@ class RoboFile extends Tasks { * * @param array $chunk */ - protected function parallelLint(array $chunk) + protected function parallelLint(array $chunk): void { $task = $this->taskParallelExec() ->timeout(5) @@ -263,7 +263,7 @@ class RoboFile extends Tasks { /** * Generate copy paste detector report */ - protected function phpcpdReport() + protected function phpcpdReport(): void { $cmd_parts = [ 'vendor/bin/phpcpd', @@ -280,7 +280,7 @@ class RoboFile extends Tasks { * @param array $cmd_parts - command arguments * @param string $join_on - what to join the command arguments with */ - protected function _run(array $cmd_parts, $join_on = ' ') + protected function _run(array $cmd_parts, $join_on = ' '): void { $this->taskExec(implode($join_on, $cmd_parts))->run(); }