Skip to content

Commit

Permalink
Merge pull request #8 from ExplodingCabbage/master
Browse files Browse the repository at this point in the history
Add return codes to allow usage in e.g. a commit hook
  • Loading branch information
bashofmann authored Aug 16, 2016
2 parents 7c245a1 + 73c29fc commit b94652c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/rg/tools/phpnsc/ClassScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(FilesystemAccess $filesystem, $root, $namespaceVendo
$this->root = $root;
$this->namespaceVendor = $namespaceVendor;
$this->output = $output;
$this->foundError = false;
}

/**
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/rg/tools/phpnsc/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions src/rg/tools/phpnsc/NamespaceDependencyChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct(FilesystemAccess $filesystem, ClassScanner $classSca
$this->root = $root;
$this->namespaceVendor = $namespaceVendor;
$this->output = $output;
$this->foundError = false;
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b94652c

Please sign in to comment.