From 73c29fc853d28496a4c6c1767c698ac4630e1b18 Mon Sep 17 00:00:00 2001 From: Mark Amery Date: Fri, 12 Aug 2016 17:18:21 +0100 Subject: [PATCH] Add return codes to allow usage in e.g. a commit hook --- src/rg/tools/phpnsc/ClassScanner.php | 3 +++ src/rg/tools/phpnsc/Command.php | 6 ++++++ src/rg/tools/phpnsc/NamespaceDependencyChecker.php | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/rg/tools/phpnsc/ClassScanner.php b/src/rg/tools/phpnsc/ClassScanner.php index d2c33fa..ed80cd9 100644 --- a/src/rg/tools/phpnsc/ClassScanner.php +++ b/src/rg/tools/phpnsc/ClassScanner.php @@ -39,6 +39,7 @@ public function __construct(FilesystemAccess $filesystem, $root, $namespaceVendo $this->root = $root; $this->namespaceVendor = $namespaceVendor; $this->output = $output; + $this->foundError = false; } /** @@ -61,10 +62,12 @@ public function parseFilesForClassesAndInterfaces($files) { if ($firstStatement instanceof Namespace_) { $namespaceOfFile = implode('\\', $firstStatement->name->parts); if ($namespace !== $namespaceOfFile) { + $this->foundError = true; $this->output->addError('Namespace does not match folder structure, got ' . $namespaceOfFile . ' expected ' . $namespace, $file, $firstStatement->getLine()); } } } catch (\PhpParser\Error $e) { + $this->foundError = true; $this->output->addError( 'Parse Error: ' . $e->getMessage(), $file, diff --git a/src/rg/tools/phpnsc/Command.php b/src/rg/tools/phpnsc/Command.php index fda6897..f5b51b0 100644 --- a/src/rg/tools/phpnsc/Command.php +++ b/src/rg/tools/phpnsc/Command.php @@ -62,5 +62,11 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $outputClass->printAll(); $outputClass->writeln(\PHP_Timer::resourceUsage()); + + if ($classScanner->foundError || $classModifier->foundError) { + return 1; + } else { + return 0; + } } } diff --git a/src/rg/tools/phpnsc/NamespaceDependencyChecker.php b/src/rg/tools/phpnsc/NamespaceDependencyChecker.php index 4167057..2d003d9 100644 --- a/src/rg/tools/phpnsc/NamespaceDependencyChecker.php +++ b/src/rg/tools/phpnsc/NamespaceDependencyChecker.php @@ -43,6 +43,7 @@ public function __construct(FilesystemAccess $filesystem, ClassScanner $classSca $this->root = $root; $this->namespaceVendor = $namespaceVendor; $this->output = $output; + $this->foundError = false; } /** @@ -147,6 +148,7 @@ private function analyzeFile($file) { } private function addMultipleErrors($description, $file, array $lines) { + $this->foundError = true; foreach ($lines as $line) { $this->output->addError($description, $file, $line); }