diff --git a/parallel-lint b/parallel-lint index cb320718..397a6c06 100755 --- a/parallel-lint +++ b/parallel-lint @@ -1,4 +1,58 @@ #!/usr/bin/env php run(); diff --git a/parallel-lint.php b/parallel-lint.php deleted file mode 100644 index 372d7252..00000000 --- a/parallel-lint.php +++ /dev/null @@ -1,132 +0,0 @@ - -Options: - -p Specify PHP-CGI executable to run (default: 'php'). - -s, --short Set short_open_tag to On (default: Off). - -a, -asp Set asp_tags to On (default: Off). - -e Check only files with selected extensions separated by comma. - (default: php,php3,php4,php5,phtml) - --exclude Exclude a file or directory. If you want exclude multiple items, - use multiple exclude parameters. - -j Run jobs in parallel (default: 10). - --colors Enable colors in console output. (disables auto detection of color support) - --no-colors Disable colors in console output. - --no-progress Disable progress in console output. - --json Output results as JSON string (require PHP 5.4). - --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. - --ignore-fails Ignore failed tests. - -h, --help Print this help. - -V, --version Display this application version - -------------------------------- -Usage: - parallel-lint [sa] [-p php] [-e ext] [-j num] [--exclude dir] [files or directories] - -json && PHP_VERSION_ID < 50400) { - throw new \Exception('JSON output require PHP version 5.4 and newer.'); - } - - if ($settings->stdin) { - $settings->addPaths(PhpParallelLint\Settings::getPathsFromStdIn()); - } - - if (empty($settings->paths)) { - showUsage(); - } - - $manager = new PhpParallelLint\Manager; - $result = $manager->run($settings); - - if ($settings->ignoreFails) { - die($result->hasSyntaxError() ? WITH_ERRORS : SUCCESS); - } else { - die($result->hasError() ? WITH_ERRORS : SUCCESS); - } - -} catch (PhpParallelLint\InvalidArgumentException $e) { - echo "Invalid option {$e->getArgument()}", PHP_EOL, PHP_EOL; - showOptions(); - die(FAILED); - -} catch (PhpParallelLint\Exception $e) { - if (isset($settings) && $settings->json) { - echo json_encode($e); - } else { - echo $e->getMessage(), PHP_EOL; - } - die(FAILED); - -} catch (Exception $e) { - echo $e->getMessage(), PHP_EOL; - die(FAILED); -} diff --git a/src/Application.php b/src/Application.php new file mode 100644 index 00000000..48ba3b93 --- /dev/null +++ b/src/Application.php @@ -0,0 +1,151 @@ +showUsage(); + } + if (in_array('-V', $_SERVER['argv']) || in_array('--version', $_SERVER['argv'])) { + $this->showVersion(); + die(); + } + try { + $settings = Settings::parseArguments($_SERVER['argv']); + if ($settings->json && PHP_VERSION_ID < 50400) { + throw new \Exception('JSON output require PHP version 5.4 and newer.'); + } + if ($settings->stdin) { + $settings->addPaths(Settings::getPathsFromStdIn()); + } + if (empty($settings->paths)) { + $this->showUsage(); + } + $manager = new Manager; + $result = $manager->run($settings); + if ($settings->ignoreFails) { + die($result->hasSyntaxError() ? self::WITH_ERRORS : self::SUCCESS); + } + die($result->hasError() ? self::WITH_ERRORS : self::SUCCESS); + } catch (InvalidArgumentException $e) { + echo "Invalid option {$e->getArgument()}", PHP_EOL, PHP_EOL; + $this->showOptions(); + die(self::FAILED); + } catch (Exception $e) { + if (isset($settings) && $settings->json) { + echo json_encode($e); + } else { + echo $e->getMessage(), PHP_EOL; + } + die(self::FAILED); + } catch (\Exception $e) { + echo $e->getMessage(), PHP_EOL; + die(self::FAILED); + } + } + + /** + * Outputs the options + */ + private function showOptions() + { + echo << Specify PHP-CGI executable to run (default: 'php'). + -s, --short Set short_open_tag to On (default: Off). + -a, -asp Set asp_tags to On (default: Off). + -e Check only files with selected extensions separated by comma. + (default: php,php3,php4,php5,phtml) + --exclude Exclude a file or directory. If you want exclude multiple items, + use multiple exclude parameters. + -j Run jobs in parallel (default: 10). + --colors Enable colors in console output. (disables auto detection of color support) + --no-colors Disable colors in console output. + --no-progress Disable progress in console output. + --json Output results as JSON string (require PHP 5.4). + --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. + --ignore-fails Ignore failed tests. + -h, --help Print this help. + -V, --version Display this application version + +HELP; + } + + /** + * Outputs the current version + */ + private function showVersion() + { + echo 'PHP Parallel Lint version '.self::VERSION.PHP_EOL; + } + + /** + * Shows usage + */ + private function showUsage() + { + $this->showVersion(); + echo <<showOptions(); + die(); + } +}