From 6514fde4a2c4559311e19adf19da1a96ffbcb681 Mon Sep 17 00:00:00 2001 From: Roelof Roos Date: Mon, 18 Jan 2021 10:27:24 +0100 Subject: [PATCH 1/5] Split files for PSR-4 compliance --- composer.json | 6 +- src/ArrayIterator.php | 11 + src/Blame.php | 37 ++ src/CheckstyleOutput.php | 78 +++ src/ConsoleWriter.php | 13 + src/Error.php | 155 ------ src/Exception.php | 17 + src/FileWriter.php | 26 + src/GitLabOutput.php | 71 +++ src/IWriter.php | 10 + src/InvalidArgumentException.php | 18 + src/JsonOutput.php | 67 +++ src/Manager.php | 92 ---- src/MultipleWriter.php | 36 ++ src/NotExistsClassException.php | 25 + src/NotExistsPathException.php | 18 + src/NotImplementCallbackException.php | 18 + src/NullWriter.php | 12 + src/Output.php | 573 ----------------------- src/RecursiveDirectoryFilterIterator.php | 96 ++++ src/RunTimeException.php | 7 + src/Settings.php | 9 - src/SyntaxError.php | 122 +++++ src/TextOutput.php | 220 +++++++++ src/TextOutputColored.php | 53 +++ src/exceptions.php | 93 ---- 26 files changed, 958 insertions(+), 925 deletions(-) create mode 100644 src/ArrayIterator.php create mode 100644 src/Blame.php create mode 100644 src/CheckstyleOutput.php create mode 100644 src/ConsoleWriter.php create mode 100644 src/Exception.php create mode 100644 src/FileWriter.php create mode 100644 src/GitLabOutput.php create mode 100644 src/IWriter.php create mode 100644 src/InvalidArgumentException.php create mode 100644 src/JsonOutput.php create mode 100644 src/MultipleWriter.php create mode 100644 src/NotExistsClassException.php create mode 100644 src/NotExistsPathException.php create mode 100644 src/NotImplementCallbackException.php create mode 100644 src/NullWriter.php create mode 100644 src/RecursiveDirectoryFilterIterator.php create mode 100644 src/RunTimeException.php create mode 100644 src/SyntaxError.php create mode 100644 src/TextOutput.php create mode 100644 src/TextOutputColored.php delete mode 100644 src/exceptions.php diff --git a/composer.json b/composer.json index 31666b4..f08a3e1 100644 --- a/composer.json +++ b/composer.json @@ -29,9 +29,9 @@ "sort-packages": true }, "autoload": { - "classmap": [ - "./src/" - ] + "psr-4": { + "JakubOnderka\\PhpParallelLint\\": "src/" + } }, "autoload-dev": { "classmap": [ diff --git a/src/ArrayIterator.php b/src/ArrayIterator.php new file mode 100644 index 0000000..b04ccb8 --- /dev/null +++ b/src/ArrayIterator.php @@ -0,0 +1,11 @@ +next(); + return $this->current(); + } +} diff --git a/src/Blame.php b/src/Blame.php new file mode 100644 index 0000000..fce8527 --- /dev/null +++ b/src/Blame.php @@ -0,0 +1,37 @@ + + * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @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( + 'name' => $this->name, + 'email' => $this->email, + 'datetime' => $this->datetime, + 'commitHash' => $this->commitHash, + 'summary' => $this->summary, + ); + } +} diff --git a/src/CheckstyleOutput.php b/src/CheckstyleOutput.php new file mode 100644 index 0000000..ea85e73 --- /dev/null +++ b/src/CheckstyleOutput.php @@ -0,0 +1,78 @@ +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) + { + $this->writer->write('' . PHP_EOL); + } + + public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails) + { + $this->writer->write('' . PHP_EOL); + $errors = array(); + + foreach ($result->getErrors() as $error) { + $message = $error->getMessage(); + if ($error instanceof SyntaxError) { + $line = $error->getLine(); + $source = "Syntax Error"; + } else { + $line = 1; + $source = "Linter Error"; + } + + $errors[$error->getShortFilePath()][] = array( + 'message' => $message, + 'line' => $line, + 'source' => $source + ); + } + + foreach ($errors as $file => $fileErrors) { + $this->writer->write(sprintf(' ', $file) . PHP_EOL); + foreach ($fileErrors as $fileError) { + $this->writer->write( + sprintf( + ' ', + $fileError['line'], + htmlspecialchars($fileError['message'], ENT_COMPAT, 'UTF-8'), + $fileError['source'] + ) . + PHP_EOL + ); + } + $this->writer->write(' ' . PHP_EOL); + } + + $this->writer->write('' . PHP_EOL); + } +} diff --git a/src/ConsoleWriter.php b/src/ConsoleWriter.php new file mode 100644 index 0000000..c226a48 --- /dev/null +++ b/src/ConsoleWriter.php @@ -0,0 +1,13 @@ + - * Specify data which should be serialized to JSON - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @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( - 'name' => $this->name, - 'email' => $this->email, - 'datetime' => $this->datetime, - 'commitHash' => $this->commitHash, - 'summary' => $this->summary, - ); - } - - -} - -class SyntaxError extends Error -{ - /** @var Blame */ - private $blame; - - /** - * @return int|null - */ - public function getLine() - { - preg_match('~on line ([0-9]+)$~', $this->message, $matches); - - if ($matches && isset($matches[1])) { - $onLine = (int) $matches[1]; - return $onLine; - } - - return null; - } - - /** - * @param bool $translateTokens - * @return mixed|string - */ - public function getNormalizedMessage($translateTokens = false) - { - $message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message); - $message = preg_replace('~ in ' . preg_quote(basename($this->filePath)) . ' on line [0-9]+$~', '', $message); - $message = ucfirst($message); - - if ($translateTokens) { - $message = $this->translateTokens($message); - } - - return $message; - } - - /** - * @param Blame $blame - */ - public function setBlame(Blame $blame) - { - $this->blame = $blame; - } - - /** - * @return Blame - */ - public function getBlame() - { - return $this->blame; - } - - /** - * @param string $message - * @return string - */ - protected function translateTokens($message) - { - static $translateTokens = array( - 'T_FILE' => '__FILE__', - 'T_FUNC_C' => '__FUNCTION__', - 'T_HALT_COMPILER' => '__halt_compiler()', - 'T_INC' => '++', - 'T_IS_EQUAL' => '==', - 'T_IS_GREATER_OR_EQUAL' => '>=', - 'T_IS_IDENTICAL' => '===', - 'T_IS_NOT_IDENTICAL' => '!==', - 'T_IS_SMALLER_OR_EQUAL' => '<=', - 'T_LINE' => '__LINE__', - 'T_METHOD_C' => '__METHOD__', - 'T_MINUS_EQUAL' => '-=', - 'T_MOD_EQUAL' => '%=', - 'T_MUL_EQUAL' => '*=', - 'T_NS_C' => '__NAMESPACE__', - 'T_NS_SEPARATOR' => '\\', - 'T_OBJECT_OPERATOR' => '->', - 'T_OR_EQUAL' => '|=', - 'T_PAAMAYIM_NEKUDOTAYIM' => '::', - 'T_PLUS_EQUAL' => '+=', - 'T_SL' => '<<', - 'T_SL_EQUAL' => '<<=', - 'T_SR' => '>>', - 'T_SR_EQUAL' => '>>=', - 'T_START_HEREDOC' => '<<<', - 'T_XOR_EQUAL' => '^=', - 'T_ECHO' => 'echo' - ); - - return preg_replace_callback('~T_([A-Z_]*)~', function ($matches) use ($translateTokens) { - list($tokenName) = $matches; - if (isset($translateTokens[$tokenName])) { - $operator = $translateTokens[$tokenName]; - return "$operator ($tokenName)"; - } - - return $tokenName; - }, $message); - } - - /** - * (PHP 5 >= 5.4.0)
- * Specify data which should be serialized to JSON - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. - */ - public function jsonSerialize() - { - return array( - 'type' => 'syntaxError', - 'file' => $this->getFilePath(), - 'line' => $this->getLine(), - 'message' => $this->getMessage(), - 'normalizeMessage' => $this->getNormalizedMessage(), - 'blame' => $this->blame, - ); - } -} \ No newline at end of file diff --git a/src/Exception.php b/src/Exception.php new file mode 100644 index 0000000..0e7cf9c --- /dev/null +++ b/src/Exception.php @@ -0,0 +1,17 @@ + get_class($this), + 'message' => $this->getMessage(), + 'code' => $this->getCode(), + ); + } +} diff --git a/src/FileWriter.php b/src/FileWriter.php new file mode 100644 index 0000000..6e43ab1 --- /dev/null +++ b/src/FileWriter.php @@ -0,0 +1,26 @@ +logFile = $logFile; + } + + public function write($string) + { + $this->buffer .= $string; + } + + public function __destruct() + { + file_put_contents($this->logFile, $this->buffer); + } +} diff --git a/src/GitLabOutput.php b/src/GitLabOutput.php new file mode 100644 index 0000000..f366be4 --- /dev/null +++ b/src/GitLabOutput.php @@ -0,0 +1,71 @@ +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); + } +} diff --git a/src/IWriter.php b/src/IWriter.php new file mode 100644 index 0000000..cce7f90 --- /dev/null +++ b/src/IWriter.php @@ -0,0 +1,10 @@ +argument = $argument; + $this->message = "Invalid argument $argument"; + } + + public function getArgument() + { + return $this->argument; + } +} diff --git a/src/JsonOutput.php b/src/JsonOutput.php new file mode 100644 index 0000000..9d26543 --- /dev/null +++ b/src/JsonOutput.php @@ -0,0 +1,67 @@ +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) + { + $this->phpVersion = $phpVersion; + $this->parallelJobs = $parallelJobs; + $this->hhvmVersion = $hhvmVersion; + } + + public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails) + { + echo json_encode(array( + 'phpVersion' => $this->phpVersion, + 'hhvmVersion' => $this->hhvmVersion, + 'parallelJobs' => $this->parallelJobs, + 'results' => $result, + )); + } +} diff --git a/src/Manager.php b/src/Manager.php index 84b7434..cb988a7 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -4,7 +4,6 @@ use JakubOnderka\PhpParallelLint\Contracts\SyntaxErrorCallback; use JakubOnderka\PhpParallelLint\Process\GitBlameProcess; use JakubOnderka\PhpParallelLint\Process\PhpExecutable; -use ReturnTypeWillChange; class Manager { @@ -200,94 +199,3 @@ protected function createSyntaxErrorCallback(Settings $settings) return $callbackInstance; } } - -class RecursiveDirectoryFilterIterator extends \RecursiveFilterIterator -{ - /** @var \RecursiveDirectoryIterator */ - private $iterator; - - /** @var array */ - private $excluded = array(); - - /** - * @param \RecursiveDirectoryIterator $iterator - * @param array $excluded - */ - public function __construct(\RecursiveDirectoryIterator $iterator, array $excluded) - { - parent::__construct($iterator); - $this->iterator = $iterator; - $this->excluded = array_map(array($this, 'getPathname'), $excluded); - } - - /** - * (PHP 5 >= 5.1.0)
- * Check whether the current element of the iterator is acceptable - * - * @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(); - $current = $this->normalizeDirectorySeparator($current); - - if ('.' . DIRECTORY_SEPARATOR !== $current[0] . $current[1]) { - $current = '.' . DIRECTORY_SEPARATOR . $current; - } - - return !in_array($current, $this->excluded); - } - - /** - * (PHP 5 >= 5.1.0)
- * Check whether the inner iterator's current element has children - * - * @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(); - } - - /** - * (PHP 5 >= 5.1.0)
- * Return the inner iterator's children contained in a RecursiveFilterIterator - * - * @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); - } - - /** - * @param string $file - * @return string - */ - private function getPathname($file) - { - $file = $this->normalizeDirectorySeparator($file); - - if ('.' . DIRECTORY_SEPARATOR !== $file[0] . $file[1]) { - $file = '.' . DIRECTORY_SEPARATOR . $file; - } - - $directoryFile = new \SplFileInfo($file); - return $directoryFile->getPathname(); - } - - /** - * @param string $file - * @return string - */ - private function normalizeDirectorySeparator($file) - { - return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $file); - } -} diff --git a/src/MultipleWriter.php b/src/MultipleWriter.php new file mode 100644 index 0000000..ca8243a --- /dev/null +++ b/src/MultipleWriter.php @@ -0,0 +1,36 @@ +addWriter($writer); + } + } + + /** + * @param IWriter $writer + */ + public function addWriter(IWriter $writer) + { + $this->writers[] = $writer; + } + + /** + * @param $string + */ + public function write($string) + { + foreach ($this->writers as $writer) { + $writer->write($string); + } + } +} diff --git a/src/NotExistsClassException.php b/src/NotExistsClassException.php new file mode 100644 index 0000000..bda23ac --- /dev/null +++ b/src/NotExistsClassException.php @@ -0,0 +1,25 @@ +className = $className; + $this->fileName = $fileName; + $this->message = "Class with name '$className' does not exists in file '$fileName'"; + } + + public function getClassName() + { + return $this->className; + } + + public function getFileName() + { + return $this->fileName; + } +} diff --git a/src/NotExistsPathException.php b/src/NotExistsPathException.php new file mode 100644 index 0000000..5bc658f --- /dev/null +++ b/src/NotExistsPathException.php @@ -0,0 +1,18 @@ +path = $path; + $this->message = "Path '$path' not found"; + } + + public function getPath() + { + return $this->path; + } +} diff --git a/src/NotImplementCallbackException.php b/src/NotImplementCallbackException.php new file mode 100644 index 0000000..6302241 --- /dev/null +++ b/src/NotImplementCallbackException.php @@ -0,0 +1,18 @@ +className = $className; + $this->message = "Class '$className' does not implement SyntaxErrorCallback interface."; + } + + public function getClassName() + { + return $this->className; + } +} diff --git a/src/NullWriter.php b/src/NullWriter.php new file mode 100644 index 0000000..52e3a61 --- /dev/null +++ b/src/NullWriter.php @@ -0,0 +1,12 @@ +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) - { - $this->phpVersion = $phpVersion; - $this->parallelJobs = $parallelJobs; - $this->hhvmVersion = $hhvmVersion; - } - - public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails) - { - echo json_encode(array( - 'phpVersion' => $this->phpVersion, - 'hhvmVersion' => $this->hhvmVersion, - 'parallelJobs' => $this->parallelJobs, - 'results' => $result, - )); - } -} - -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', - TYPE_SKIP = 'skip', - TYPE_ERROR = 'error', - TYPE_FAIL = 'fail', - TYPE_OK = 'ok'; - - /** @var int */ - public $filesPerLine = 60; - - /** @var bool */ - public $showProgress = true; - - /** @var int */ - protected $checkedFiles; - - /** @var int */ - protected $totalFileCount; - - /** @var IWriter */ - protected $writer; - - /** - * @param IWriter $writer - */ - public function __construct(IWriter $writer) - { - $this->writer = $writer; - } - - public function ok() - { - $this->writeMark(self::TYPE_OK); - } - - public function skip() - { - $this->writeMark(self::TYPE_SKIP); - } - - public function error() - { - $this->writeMark(self::TYPE_ERROR); - } - - public function fail() - { - $this->writeMark(self::TYPE_FAIL); - } - - /** - * @param string $string - * @param string $type - */ - public function write($string, $type = self::TYPE_DEFAULT) - { - $this->writer->write($string); - } - - /** - * @param string|null $line - * @param string $type - */ - public function writeLine($line = null, $type = self::TYPE_DEFAULT) - { - $this->write($line, $type); - $this->writeNewLine(); - } - - /** - * @param int $count - */ - public function writeNewLine($count = 1) - { - $this->write(str_repeat(PHP_EOL, $count)); - } - - /** - * @param int $count - */ - public function setTotalFileCount($count) - { - $this->totalFileCount = $count; - } - - /** - * @param int $phpVersion - * @param int $parallelJobs - * @param string $hhvmVersion - */ - public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null) - { - $this->write("PHP {$this->phpVersionIdToString($phpVersion)} | "); - - if ($hhvmVersion) { - $this->write("HHVM $hhvmVersion | "); - } - - if ($parallelJobs === 1) { - $this->writeLine("1 job"); - } else { - $this->writeLine("{$parallelJobs} parallel jobs"); - } - } - - /** - * @param Result $result - * @param ErrorFormatter $errorFormatter - * @param bool $ignoreFails - */ - public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails) - { - if ($this->showProgress) { - if ($this->checkedFiles % $this->filesPerLine !== 0) { - $rest = $this->filesPerLine - ($this->checkedFiles % $this->filesPerLine); - $this->write(str_repeat(' ', $rest)); - $this->writePercent(); - } - - $this->writeNewLine(2); - } - - $testTime = round($result->getTestTime(), 1); - $message = "Checked {$result->getCheckedFilesCount()} files in $testTime "; - $message .= $testTime == 1 ? 'second' : 'seconds'; - - if ($result->getSkippedFilesCount() > 0) { - $message .= ", skipped {$result->getSkippedFilesCount()} "; - $message .= ($result->getSkippedFilesCount() === 1 ? 'file' : 'files'); - } - - $this->writeLine($message); - - if (!$result->hasSyntaxError()) { - $message = "No syntax error found"; - } else { - $message = "Syntax error found in {$result->getFilesWithSyntaxErrorCount()} "; - $message .= ($result->getFilesWithSyntaxErrorCount() === 1 ? 'file' : 'files'); - } - - if ($result->hasFilesWithFail()) { - $message .= ", failed to check {$result->getFilesWithFailCount()} "; - $message .= ($result->getFilesWithFailCount() === 1 ? 'file' : 'files'); - - if ($ignoreFails) { - $message .= ' (ignored)'; - } - } - - $hasError = $ignoreFails ? $result->hasSyntaxError() : $result->hasError(); - $this->writeLine($message, $hasError ? self::TYPE_ERROR : self::TYPE_OK); - - if ($result->hasError()) { - $this->writeNewLine(); - foreach ($result->getErrors() as $error) { - $this->writeLine(str_repeat('-', 60)); - $this->writeLine($errorFormatter->format($error)); - } - } - } - - protected function writeMark($type) - { - ++$this->checkedFiles; - - if ($this->showProgress) { - if ($type === self::TYPE_OK) { - $this->writer->write('.'); - - } else if ($type === self::TYPE_SKIP) { - $this->write('S', self::TYPE_SKIP); - - } else if ($type === self::TYPE_ERROR) { - $this->write('X', self::TYPE_ERROR); - - } else if ($type === self::TYPE_FAIL) { - $this->writer->write('-'); - } - - if ($this->checkedFiles % $this->filesPerLine === 0) { - $this->writePercent(); - } - } - } - - protected function writePercent() - { - $percent = floor($this->checkedFiles / $this->totalFileCount * 100); - $current = $this->stringWidth($this->checkedFiles, strlen($this->totalFileCount)); - $this->writeLine(" $current/$this->totalFileCount ($percent %)"); - } - - /** - * @param string $input - * @param int $width - * @return string - */ - protected function stringWidth($input, $width = 3) - { - $multiplier = $width - strlen($input); - return str_repeat(' ', $multiplier > 0 ? $multiplier : 0) . $input; - } - - /** - * @param int $phpVersionId - * @return string - */ - protected function phpVersionIdToString($phpVersionId) - { - $releaseVersion = (int) substr($phpVersionId, -2, 2); - $minorVersion = (int) substr($phpVersionId, -4, 2); - $majorVersion = (int) substr($phpVersionId, 0, strlen($phpVersionId) - 4); - - return "$majorVersion.$minorVersion.$releaseVersion"; - } -} - -class CheckstyleOutput implements Output -{ - private $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) - { - $this->writer->write('' . PHP_EOL); - } - - public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails) - { - $this->writer->write('' . PHP_EOL); - $errors = array(); - - foreach ($result->getErrors() as $error) { - $message = $error->getMessage(); - if ($error instanceof SyntaxError) { - $line = $error->getLine(); - $source = "Syntax Error"; - } else { - $line = 1; - $source = "Linter Error"; - } - - $errors[$error->getShortFilePath()][] = array( - 'message' => $message, - 'line' => $line, - 'source' => $source - ); - } - - foreach ($errors as $file => $fileErrors) { - $this->writer->write(sprintf(' ', $file) . PHP_EOL); - foreach ($fileErrors as $fileError) { - $this->writer->write( - sprintf( - ' ', - $fileError['line'], - htmlspecialchars($fileError['message'], ENT_COMPAT, 'UTF-8'), - $fileError['source'] - ) . - PHP_EOL - ); - } - $this->writer->write(' ' . PHP_EOL); - } - - $this->writer->write('' . PHP_EOL); - } -} - -class TextOutputColored extends TextOutput -{ - /** @var \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor|\JakubOnderka\PhpConsoleColor\ConsoleColor */ - private $colors; - - public function __construct(IWriter $writer, $colors = Settings::AUTODETECT) - { - parent::__construct($writer); - - if (class_exists('\PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor')) { - $this->colors = new \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor(); - $this->colors->setForceStyle($colors === Settings::FORCED); - } else if (class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor')) { - $this->colors = new \JakubOnderka\PhpConsoleColor\ConsoleColor(); - $this->colors->setForceStyle($colors === Settings::FORCED); - } - } - - /** - * @param string $string - * @param string $type - * @throws \PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException|\JakubOnderka\PhpConsoleColor\InvalidStyleException - */ - public function write($string, $type = self::TYPE_DEFAULT) - { - if ( - !$this->colors instanceof \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor - && !$this->colors instanceof \JakubOnderka\PhpConsoleColor\ConsoleColor - ) { - parent::write($string, $type); - } else { - switch ($type) { - case self::TYPE_OK: - parent::write($this->colors->apply('bg_green', $string)); - break; - - case self::TYPE_SKIP: - parent::write($this->colors->apply('bg_yellow', $string)); - break; - - case self::TYPE_ERROR: - parent::write($this->colors->apply('bg_red', $string)); - break; - - default: - parent::write($string); - } - } - } -} - -interface IWriter -{ - /** - * @param string $string - */ - public function write($string); -} - -class NullWriter implements IWriter -{ - /** - * @param string $string - */ - public function write($string) - { - - } -} - -class ConsoleWriter implements IWriter -{ - /** - * @param string $string - */ - public function write($string) - { - echo $string; - } -} - -class FileWriter implements IWriter -{ - /** @var string */ - protected $logFile; - - /** @var string */ - protected $buffer; - - public function __construct($logFile) - { - $this->logFile = $logFile; - } - - public function write($string) - { - $this->buffer .= $string; - } - - public function __destruct() - { - file_put_contents($this->logFile, $this->buffer); - } -} - -class MultipleWriter implements IWriter -{ - /** @var IWriter[] */ - protected $writers; - - /** - * @param IWriter[] $writers - */ - public function __construct(array $writers) - { - foreach ($writers as $writer) { - $this->addWriter($writer); - } - } - - /** - * @param IWriter $writer - */ - public function addWriter(IWriter $writer) - { - $this->writers[] = $writer; - } - - /** - * @param $string - */ - public function write($string) - { - foreach ($this->writers as $writer) { - $writer->write($string); - } - } -} diff --git a/src/RecursiveDirectoryFilterIterator.php b/src/RecursiveDirectoryFilterIterator.php new file mode 100644 index 0000000..b3879fd --- /dev/null +++ b/src/RecursiveDirectoryFilterIterator.php @@ -0,0 +1,96 @@ +iterator = $iterator; + $this->excluded = array_map(array($this, 'getPathname'), $excluded); + } + + /** + * (PHP 5 >= 5.1.0)
+ * Check whether the current element of the iterator is acceptable + * + * @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(); + $current = $this->normalizeDirectorySeparator($current); + + if ('.' . DIRECTORY_SEPARATOR !== $current[0] . $current[1]) { + $current = '.' . DIRECTORY_SEPARATOR . $current; + } + + return !in_array($current, $this->excluded); + } + + /** + * (PHP 5 >= 5.1.0)
+ * Check whether the inner iterator's current element has children + * + * @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(); + } + + /** + * (PHP 5 >= 5.1.0)
+ * Return the inner iterator's children contained in a RecursiveFilterIterator + * + * @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); + } + + /** + * @param string $file + * @return string + */ + private function getPathname($file) + { + $file = $this->normalizeDirectorySeparator($file); + + if ('.' . DIRECTORY_SEPARATOR !== $file[0] . $file[1]) { + $file = '.' . DIRECTORY_SEPARATOR . $file; + } + + $directoryFile = new \SplFileInfo($file); + return $directoryFile->getPathname(); + } + + /** + * @param string $file + * @return string + */ + private function normalizeDirectorySeparator($file) + { + return str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $file); + } +} diff --git a/src/RunTimeException.php b/src/RunTimeException.php new file mode 100644 index 0000000..303254d --- /dev/null +++ b/src/RunTimeException.php @@ -0,0 +1,7 @@ +next(); - return $this->current(); - } -} diff --git a/src/SyntaxError.php b/src/SyntaxError.php new file mode 100644 index 0000000..f60b9fe --- /dev/null +++ b/src/SyntaxError.php @@ -0,0 +1,122 @@ +message, $matches); + + if ($matches && isset($matches[1])) { + $onLine = (int) $matches[1]; + return $onLine; + } + + return null; + } + + /** + * @param bool $translateTokens + * @return mixed|string + */ + public function getNormalizedMessage($translateTokens = false) + { + $message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message); + $message = preg_replace('~ in ' . preg_quote(basename($this->filePath)) . ' on line [0-9]+$~', '', $message); + $message = ucfirst($message); + + if ($translateTokens) { + $message = $this->translateTokens($message); + } + + return $message; + } + + /** + * @param Blame $blame + */ + public function setBlame(Blame $blame) + { + $this->blame = $blame; + } + + /** + * @return Blame + */ + public function getBlame() + { + return $this->blame; + } + + /** + * @param string $message + * @return string + */ + protected function translateTokens($message) + { + static $translateTokens = array( + 'T_FILE' => '__FILE__', + 'T_FUNC_C' => '__FUNCTION__', + 'T_HALT_COMPILER' => '__halt_compiler()', + 'T_INC' => '++', + 'T_IS_EQUAL' => '==', + 'T_IS_GREATER_OR_EQUAL' => '>=', + 'T_IS_IDENTICAL' => '===', + 'T_IS_NOT_IDENTICAL' => '!==', + 'T_IS_SMALLER_OR_EQUAL' => '<=', + 'T_LINE' => '__LINE__', + 'T_METHOD_C' => '__METHOD__', + 'T_MINUS_EQUAL' => '-=', + 'T_MOD_EQUAL' => '%=', + 'T_MUL_EQUAL' => '*=', + 'T_NS_C' => '__NAMESPACE__', + 'T_NS_SEPARATOR' => '\\', + 'T_OBJECT_OPERATOR' => '->', + 'T_OR_EQUAL' => '|=', + 'T_PAAMAYIM_NEKUDOTAYIM' => '::', + 'T_PLUS_EQUAL' => '+=', + 'T_SL' => '<<', + 'T_SL_EQUAL' => '<<=', + 'T_SR' => '>>', + 'T_SR_EQUAL' => '>>=', + 'T_START_HEREDOC' => '<<<', + 'T_XOR_EQUAL' => '^=', + 'T_ECHO' => 'echo' + ); + + return preg_replace_callback('~T_([A-Z_]*)~', function ($matches) use ($translateTokens) { + list($tokenName) = $matches; + if (isset($translateTokens[$tokenName])) { + $operator = $translateTokens[$tokenName]; + return "$operator ($tokenName)"; + } + + return $tokenName; + }, $message); + } + + /** + * (PHP 5 >= 5.4.0)
+ * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + */ + public function jsonSerialize() + { + return array( + 'type' => 'syntaxError', + 'file' => $this->getFilePath(), + 'line' => $this->getLine(), + 'message' => $this->getMessage(), + 'normalizeMessage' => $this->getNormalizedMessage(), + 'blame' => $this->blame, + ); + } +} \ No newline at end of file diff --git a/src/TextOutput.php b/src/TextOutput.php new file mode 100644 index 0000000..7c3e571 --- /dev/null +++ b/src/TextOutput.php @@ -0,0 +1,220 @@ +writer = $writer; + } + + public function ok() + { + $this->writeMark(self::TYPE_OK); + } + + public function skip() + { + $this->writeMark(self::TYPE_SKIP); + } + + public function error() + { + $this->writeMark(self::TYPE_ERROR); + } + + public function fail() + { + $this->writeMark(self::TYPE_FAIL); + } + + /** + * @param string $string + * @param string $type + */ + public function write($string, $type = self::TYPE_DEFAULT) + { + $this->writer->write($string); + } + + /** + * @param string|null $line + * @param string $type + */ + public function writeLine($line = null, $type = self::TYPE_DEFAULT) + { + $this->write($line, $type); + $this->writeNewLine(); + } + + /** + * @param int $count + */ + public function writeNewLine($count = 1) + { + $this->write(str_repeat(PHP_EOL, $count)); + } + + /** + * @param int $count + */ + public function setTotalFileCount($count) + { + $this->totalFileCount = $count; + } + + /** + * @param int $phpVersion + * @param int $parallelJobs + * @param string $hhvmVersion + */ + public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null) + { + $this->write("PHP {$this->phpVersionIdToString($phpVersion)} | "); + + if ($hhvmVersion) { + $this->write("HHVM $hhvmVersion | "); + } + + if ($parallelJobs === 1) { + $this->writeLine("1 job"); + } else { + $this->writeLine("{$parallelJobs} parallel jobs"); + } + } + + /** + * @param Result $result + * @param ErrorFormatter $errorFormatter + * @param bool $ignoreFails + */ + public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails) + { + if ($this->showProgress) { + if ($this->checkedFiles % $this->filesPerLine !== 0) { + $rest = $this->filesPerLine - ($this->checkedFiles % $this->filesPerLine); + $this->write(str_repeat(' ', $rest)); + $this->writePercent(); + } + + $this->writeNewLine(2); + } + + $testTime = round($result->getTestTime(), 1); + $message = "Checked {$result->getCheckedFilesCount()} files in $testTime "; + $message .= $testTime == 1 ? 'second' : 'seconds'; + + if ($result->getSkippedFilesCount() > 0) { + $message .= ", skipped {$result->getSkippedFilesCount()} "; + $message .= ($result->getSkippedFilesCount() === 1 ? 'file' : 'files'); + } + + $this->writeLine($message); + + if (!$result->hasSyntaxError()) { + $message = "No syntax error found"; + } else { + $message = "Syntax error found in {$result->getFilesWithSyntaxErrorCount()} "; + $message .= ($result->getFilesWithSyntaxErrorCount() === 1 ? 'file' : 'files'); + } + + if ($result->hasFilesWithFail()) { + $message .= ", failed to check {$result->getFilesWithFailCount()} "; + $message .= ($result->getFilesWithFailCount() === 1 ? 'file' : 'files'); + + if ($ignoreFails) { + $message .= ' (ignored)'; + } + } + + $hasError = $ignoreFails ? $result->hasSyntaxError() : $result->hasError(); + $this->writeLine($message, $hasError ? self::TYPE_ERROR : self::TYPE_OK); + + if ($result->hasError()) { + $this->writeNewLine(); + foreach ($result->getErrors() as $error) { + $this->writeLine(str_repeat('-', 60)); + $this->writeLine($errorFormatter->format($error)); + } + } + } + + protected function writeMark($type) + { + ++$this->checkedFiles; + + if ($this->showProgress) { + if ($type === self::TYPE_OK) { + $this->writer->write('.'); + + } else if ($type === self::TYPE_SKIP) { + $this->write('S', self::TYPE_SKIP); + + } else if ($type === self::TYPE_ERROR) { + $this->write('X', self::TYPE_ERROR); + + } else if ($type === self::TYPE_FAIL) { + $this->writer->write('-'); + } + + if ($this->checkedFiles % $this->filesPerLine === 0) { + $this->writePercent(); + } + } + } + + protected function writePercent() + { + $percent = floor($this->checkedFiles / $this->totalFileCount * 100); + $current = $this->stringWidth($this->checkedFiles, strlen($this->totalFileCount)); + $this->writeLine(" $current/$this->totalFileCount ($percent %)"); + } + + /** + * @param string $input + * @param int $width + * @return string + */ + protected function stringWidth($input, $width = 3) + { + $multiplier = $width - strlen($input); + return str_repeat(' ', $multiplier > 0 ? $multiplier : 0) . $input; + } + + /** + * @param int $phpVersionId + * @return string + */ + protected function phpVersionIdToString($phpVersionId) + { + $releaseVersion = (int) substr($phpVersionId, -2, 2); + $minorVersion = (int) substr($phpVersionId, -4, 2); + $majorVersion = (int) substr($phpVersionId, 0, strlen($phpVersionId) - 4); + + return "$majorVersion.$minorVersion.$releaseVersion"; + } +} diff --git a/src/TextOutputColored.php b/src/TextOutputColored.php new file mode 100644 index 0000000..9c0240a --- /dev/null +++ b/src/TextOutputColored.php @@ -0,0 +1,53 @@ +colors = new \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor(); + $this->colors->setForceStyle($colors === Settings::FORCED); + } else if (class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor')) { + $this->colors = new \JakubOnderka\PhpConsoleColor\ConsoleColor(); + $this->colors->setForceStyle($colors === Settings::FORCED); + } + } + + /** + * @param string $string + * @param string $type + * @throws \PHP_Parallel_Lint\PhpConsoleColor\InvalidStyleException|\JakubOnderka\PhpConsoleColor\InvalidStyleException + */ + public function write($string, $type = self::TYPE_DEFAULT) + { + if ( + !$this->colors instanceof \PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor + && !$this->colors instanceof \JakubOnderka\PhpConsoleColor\ConsoleColor + ) { + parent::write($string, $type); + } else { + switch ($type) { + case self::TYPE_OK: + parent::write($this->colors->apply('bg_green', $string)); + break; + + case self::TYPE_SKIP: + parent::write($this->colors->apply('bg_yellow', $string)); + break; + + case self::TYPE_ERROR: + parent::write($this->colors->apply('bg_red', $string)); + break; + + default: + parent::write($string); + } + } + } +} diff --git a/src/exceptions.php b/src/exceptions.php deleted file mode 100644 index b96f28a..0000000 --- a/src/exceptions.php +++ /dev/null @@ -1,93 +0,0 @@ - get_class($this), - 'message' => $this->getMessage(), - 'code' => $this->getCode(), - ); - } -} - -class RunTimeException extends Exception -{ - -} - -class InvalidArgumentException extends Exception -{ - protected $argument; - - public function __construct($argument) - { - $this->argument = $argument; - $this->message = "Invalid argument $argument"; - } - - public function getArgument() - { - return $this->argument; - } -} - -class NotExistsPathException extends Exception -{ - protected $path; - - public function __construct($path) - { - $this->path = $path; - $this->message = "Path '$path' not found"; - } - - public function getPath() - { - return $this->path; - } -} - -class NotExistsClassException extends Exception -{ - protected $className; - protected $fileName; - - public function __construct($className, $fileName) - { - $this->className = $className; - $this->fileName = $fileName; - $this->message = "Class with name '$className' does not exists in file '$fileName'"; - } - - public function getClassName() - { - return $this->className; - } - - public function getFileName() - { - return $this->fileName; - } -} - -class NotImplementCallbackException extends Exception -{ - protected $className; - - public function __construct($className) - { - $this->className = $className; - $this->message = "Class '$className' does not implement SyntaxErrorCallback interface."; - } - - public function getClassName() - { - return $this->className; - } -} From ef8089d1c7a4eb59386fb6b29cae7755436f957a Mon Sep 17 00:00:00 2001 From: Roelof Roos Date: Mon, 22 Mar 2021 00:16:43 +0100 Subject: [PATCH 2/5] Re-namespace and re-structure codebase --- composer.json | 2 +- doc/syntax-error-callback.md | 6 +-- parallel-lint | 2 +- src/Application.php | 7 +++- src/Blame.php | 2 +- src/Contracts/SyntaxErrorCallback.php | 4 +- src/ErrorFormatter.php | 8 ++-- .../ParallelLintError.php} | 4 +- src/{ => Errors}/SyntaxError.php | 6 ++- .../InvalidArgumentException.php | 4 +- .../NotExistsClassException.php | 4 +- .../NotExistsPathException.php | 4 +- .../NotImplementCallbackException.php | 4 +- .../ParallelLintException.php} | 4 +- src/Exceptions/RuntimeException.php | 7 ++++ src/{ => Iterators}/ArrayIterator.php | 2 +- .../RecursiveDirectoryFilterIterator.php | 2 +- src/Manager.php | 38 ++++++++++++------- src/{ => Outputs}/CheckstyleOutput.php | 11 ++++-- src/{ => Outputs}/GitLabOutput.php | 16 +++++--- src/{ => Outputs}/JsonOutput.php | 14 ++++--- .../OutputInterface.php} | 10 +++-- src/{ => Outputs}/TextOutput.php | 14 ++++--- src/{ => Outputs}/TextOutputColored.php | 7 +++- src/ParallelLint.php | 23 ++++++----- src/Process/GitBlameProcess.php | 30 +++++++-------- src/Process/LintProcess.php | 17 +++++---- src/Process/PhpExecutable.php | 14 +++---- src/Process/PhpProcess.php | 4 +- src/Process/Process.php | 22 +++++------ src/Process/SkipLintProcess.php | 12 +++--- src/Result.php | 10 +++-- src/RunTimeException.php | 7 ---- src/Settings.php | 5 ++- src/{ => Writers}/ConsoleWriter.php | 4 +- src/{ => Writers}/FileWriter.php | 4 +- src/{ => Writers}/MultipleWriter.php | 14 +++---- src/{ => Writers}/NullWriter.php | 4 +- .../WriterInterface.php} | 4 +- tests/Manager.run.phpt | 14 +++---- tests/Output.phpt | 21 +++++----- tests/ParallelLint.lint.phpt | 4 +- tests/Settings.parseArguments.phpt | 2 +- tests/SkipLintProcess.phpt | 4 +- tests/SyntaxError.normalizeMessage.phpt | 2 +- 45 files changed, 229 insertions(+), 174 deletions(-) rename src/{Error.php => Errors/ParallelLintError.php} (93%) rename src/{ => Errors}/SyntaxError.php (96%) rename src/{ => Exceptions}/InvalidArgumentException.php (69%) rename src/{ => Exceptions}/NotExistsClassException.php (80%) rename src/{ => Exceptions}/NotExistsPathException.php (67%) rename src/{ => Exceptions}/NotImplementCallbackException.php (72%) rename src/{Exception.php => Exceptions/ParallelLintException.php} (67%) create mode 100644 src/Exceptions/RuntimeException.php rename src/{ => Iterators}/ArrayIterator.php (74%) rename src/{ => Iterators}/RecursiveDirectoryFilterIterator.php (98%) rename src/{ => Outputs}/CheckstyleOutput.php (83%) rename src/{ => Outputs}/GitLabOutput.php (74%) rename src/{ => Outputs}/JsonOutput.php (72%) rename src/{Output.php => Outputs/OutputInterface.php} (54%) rename src/{ => Outputs}/TextOutput.php (93%) rename src/{ => Outputs}/TextOutputColored.php (87%) delete mode 100644 src/RunTimeException.php rename src/{ => Writers}/ConsoleWriter.php (56%) rename src/{ => Writers}/FileWriter.php (80%) rename src/{ => Writers}/MultipleWriter.php (58%) rename src/{ => Writers}/NullWriter.php (52%) rename src/{IWriter.php => Writers/WriterInterface.php} (54%) diff --git a/composer.json b/composer.json index f08a3e1..8755a07 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ }, "autoload": { "psr-4": { - "JakubOnderka\\PhpParallelLint\\": "src/" + "PhpParallelLint\\PhpParallelLint\\": "src/" } }, "autoload-dev": { diff --git a/doc/syntax-error-callback.md b/doc/syntax-error-callback.md index 955f5ef..89c980f 100644 --- a/doc/syntax-error-callback.md +++ b/doc/syntax-error-callback.md @@ -1,7 +1,7 @@ # Syntax Error Callback 1. Set a path to a file with custom error callback to `--syntax-error-callback` option. -1. Create a class implementing `JakubOnderka\PhpParallelLint\Contracts\SyntaxErrorCallback` interface. File with the class must have the same name as the class inside. +1. Create a class implementing `PhpParallelLint\PhpParallelLint\Contracts\SyntaxErrorCallback` interface. File with the class must have the same name as the class inside. 1. Modify error before it is printed to the output. ## Example configuration @@ -11,8 +11,8 @@ The content should look like: ```php -use JakubOnderka\PhpParallelLint\Contracts\SyntaxErrorCallback; -use JakubOnderka\PhpParallelLint\SyntaxError; +use PhpParallelLint\PhpParallelLint\Contracts\SyntaxErrorCallback; +use PhpParallelLint\PhpParallelLint\Errors\SyntaxError; class MyCustomErrorHandler implements SyntaxErrorCallback { /** diff --git a/parallel-lint b/parallel-lint index 256425c..0100c93 100755 --- a/parallel-lint +++ b/parallel-lint @@ -70,5 +70,5 @@ if (!$loaded) { require_once __DIR__ . '/src/polyfill.php'; -$app = new JakubOnderka\PhpParallelLint\Application(); +$app = new PhpParallelLint\PhpParallelLint\Application(); exit($app->run()); diff --git a/src/Application.php b/src/Application.php index b94e3c9..8bb0ee1 100644 --- a/src/Application.php +++ b/src/Application.php @@ -1,6 +1,9 @@ showOptions(); return self::FAILED; - } catch (Exception $e) { + } catch (ParallelLintException $e) { if (isset($settings) && $settings->format === Settings::FORMAT_JSON) { echo json_encode($e); } else { diff --git a/src/Blame.php b/src/Blame.php index fce8527..d88c197 100644 --- a/src/Blame.php +++ b/src/Blame.php @@ -1,5 +1,5 @@ formatSyntaxErrorMessage($error); diff --git a/src/Error.php b/src/Errors/ParallelLintError.php similarity index 93% rename from src/Error.php rename to src/Errors/ParallelLintError.php index 7b9d244..54c3778 100644 --- a/src/Error.php +++ b/src/Errors/ParallelLintError.php @@ -1,9 +1,9 @@ getFilesFromPaths($settings->paths, $settings->extensions, $settings->excluded); if (empty($files)) { - throw new Exception('No file found to check.'); + throw new ParallelLintException('No file found to check.'); } $output->setTotalFileCount(count($files)); @@ -65,16 +77,16 @@ public function run(Settings $settings = null) } /** - * @param Output $output + * @param OutputInterface $output */ - public function setOutput(Output $output) + public function setOutput(OutputInterface $output) { $this->output = $output; } /** * @param Settings $settings - * @return Output + * @return OutputInterface */ protected function getDefaultOutput(Settings $settings) { @@ -102,7 +114,7 @@ protected function getDefaultOutput(Settings $settings) /** * @param Result $result * @param Settings $settings - * @throws Exception + * @throws ParallelLintException */ protected function gitBlame(Result $result, Settings $settings) { diff --git a/src/CheckstyleOutput.php b/src/Outputs/CheckstyleOutput.php similarity index 83% rename from src/CheckstyleOutput.php rename to src/Outputs/CheckstyleOutput.php index ea85e73..16fdf31 100644 --- a/src/CheckstyleOutput.php +++ b/src/Outputs/CheckstyleOutput.php @@ -1,11 +1,16 @@ writer = $writer; } diff --git a/src/GitLabOutput.php b/src/Outputs/GitLabOutput.php similarity index 74% rename from src/GitLabOutput.php rename to src/Outputs/GitLabOutput.php index f366be4..1160e67 100644 --- a/src/GitLabOutput.php +++ b/src/Outputs/GitLabOutput.php @@ -1,15 +1,21 @@ writer = $writer; } diff --git a/src/JsonOutput.php b/src/Outputs/JsonOutput.php similarity index 72% rename from src/JsonOutput.php rename to src/Outputs/JsonOutput.php index 9d26543..191700f 100644 --- a/src/JsonOutput.php +++ b/src/Outputs/JsonOutput.php @@ -1,9 +1,13 @@ writer = $writer; } diff --git a/src/Output.php b/src/Outputs/OutputInterface.php similarity index 54% rename from src/Output.php rename to src/Outputs/OutputInterface.php index 1d3ce1e..25d5f1b 100644 --- a/src/Output.php +++ b/src/Outputs/OutputInterface.php @@ -1,9 +1,13 @@ writer = $writer; } diff --git a/src/TextOutputColored.php b/src/Outputs/TextOutputColored.php similarity index 87% rename from src/TextOutputColored.php rename to src/Outputs/TextOutputColored.php index 9c0240a..e7b79d2 100644 --- a/src/TextOutputColored.php +++ b/src/Outputs/TextOutputColored.php @@ -1,12 +1,15 @@ processCallback) ? $this->processCallback : function () { }; + $errors = $running = $waiting = array(); + $skippedFiles = $checkedFiles = array(); + /** * @var LintProcess[] $running * @var LintProcess[] $waiting */ - $errors = $running = $waiting = array(); - $skippedFiles = $checkedFiles = array(); while ($files || $running) { for ($i = count($running); $files && $i < $this->parallelJobs; $i++) { @@ -105,7 +108,7 @@ public function lint(array $files) } else { - $errors[] = new Error($file, $process->getOutput()); + $errors[] = new ParallelLintError($file, $process->getOutput()); $processCallback(self::STATUS_FAIL, $file); } } @@ -139,7 +142,7 @@ public function lint(array $files) $processCallback(self::STATUS_ERROR, $file); } else { - $errors[] = new Error($file, $process->getOutput()); + $errors[] = new ParallelLintError($file, $process->getOutput()); $processCallback(self::STATUS_FAIL, $file); } } @@ -254,7 +257,7 @@ public function isShowDeprecated() } /** - * @param $showDeprecated + * @param bool $showDeprecated * @return ParallelLint */ public function setShowDeprecated($showDeprecated) diff --git a/src/Process/GitBlameProcess.php b/src/Process/GitBlameProcess.php index 2d675b8..f90772d 100644 --- a/src/Process/GitBlameProcess.php +++ b/src/Process/GitBlameProcess.php @@ -1,7 +1,7 @@ isSuccess()) { - throw new RunTimeException("Author can only be retrieved for successful process output."); + throw new RuntimeException("Author can only be retrieved for successful process output."); } $output = $this->getOutput(); @@ -43,12 +43,12 @@ public function getAuthor() /** * @return string - * @throws RunTimeException + * @throws RuntimeException */ public function getAuthorEmail() { if (!$this->isSuccess()) { - throw new RunTimeException("Author e-mail can only be retrieved for successful process output."); + throw new RuntimeException("Author e-mail can only be retrieved for successful process output."); } $output = $this->getOutput(); @@ -58,12 +58,12 @@ public function getAuthorEmail() /** * @return \DateTime - * @throws RunTimeException + * @throws RuntimeException */ public function getAuthorTime() { if (!$this->isSuccess()) { - throw new RunTimeException("Author time can only be retrieved for successful process output."); + throw new RuntimeException("Author time can only be retrieved for successful process output."); } $output = $this->getOutput(); @@ -79,12 +79,12 @@ public function getAuthorTime() /** * @return string - * @throws RunTimeException + * @throws RuntimeException */ public function getCommitHash() { if (!$this->isSuccess()) { - throw new RunTimeException("Commit hash can only be retrieved for successful process output."); + throw new RuntimeException("Commit hash can only be retrieved for successful process output."); } return substr($this->getOutput(), 0, strpos($this->getOutput(), ' ')); @@ -92,12 +92,12 @@ public function getCommitHash() /** * @return string - * @throws RunTimeException + * @throws RuntimeException */ public function getSummary() { if (!$this->isSuccess()) { - throw new RunTimeException("Commit summary can only be retrieved for successful process output."); + throw new RuntimeException("Commit summary can only be retrieved for successful process output."); } $output = $this->getOutput(); @@ -108,7 +108,7 @@ public function getSummary() /** * @param string $gitExecutable * @return bool - * @throws RunTimeException + * @throws RuntimeException */ public static function gitExists($gitExecutable) { diff --git a/src/Process/LintProcess.php b/src/Process/LintProcess.php index e2e6b2d..568ba50 100644 --- a/src/Process/LintProcess.php +++ b/src/Process/LintProcess.php @@ -1,7 +1,8 @@ getOutput()}' does not contain Parse or Syntax errors"); + throw new RuntimeException("The output '{$this->getOutput()}' does not contain Parse or Syntax errors"); } return false; @@ -88,7 +89,7 @@ public function getSyntaxError() /** * @return bool - * @throws RunTimeException + * @throws RuntimeException */ public function isFail() { @@ -97,7 +98,7 @@ public function isFail() /** * @return bool - * @throws RunTimeException + * @throws RuntimeException */ public function isSuccess() { diff --git a/src/Process/PhpExecutable.php b/src/Process/PhpExecutable.php index 001b1e9..068acbd 100644 --- a/src/Process/PhpExecutable.php +++ b/src/Process/PhpExecutable.php @@ -1,8 +1,8 @@ getStatusCode() !== 0 && $process->getStatusCode() !== 255) { - throw new RunTimeException("Unable to execute '{$phpExecutable}'."); + throw new RuntimeException("Unable to execute '{$phpExecutable}'."); } return self::getPhpExecutableFromOutput($phpExecutable, $process->getOutput()); - } catch (RunTimeException $e) { + } catch (RuntimeException $e) { // Try HHVM type $process = new Process($phpExecutable, array('--php', '-r', $codeToExecute)); $process->waitForFinish(); if ($process->getStatusCode() !== 0 && $process->getStatusCode() !== 255) { - throw new RunTimeException("Unable to execute '{$phpExecutable}'."); + throw new RuntimeException("Unable to execute '{$phpExecutable}'."); } return self::getPhpExecutableFromOutput($phpExecutable, $process->getOutput(), $isHhvmType = true); @@ -106,14 +106,14 @@ public static function getPhpExecutable($phpExecutable) * @param string $output * @param bool $isHhvmType * @return PhpExecutable - * @throws RunTimeException + * @throws RuntimeException */ private static function getPhpExecutableFromOutput($phpExecutable, $output, $isHhvmType = false) { $parts = explode(';', $output); if ($parts[0] !== 'PHP' || !preg_match('~([0-9]+)~', $parts[1], $matches)) { - throw new RunTimeException("'{$phpExecutable}' is not valid PHP binary."); + throw new RuntimeException("'{$phpExecutable}' is not valid PHP binary."); } $hhvmVersion = isset($parts[2]) ? $parts[2] : false; diff --git a/src/Process/PhpProcess.php b/src/Process/PhpProcess.php index 0df293a..43fb5f3 100644 --- a/src/Process/PhpProcess.php +++ b/src/Process/PhpProcess.php @@ -1,6 +1,6 @@ process = proc_open($cmdLine, $descriptors, $pipes, null, null, array('bypass_shell' => true)); if ($this->process === false || $this->process === null) { - throw new RunTimeException("Cannot create new process $cmdLine"); + throw new RuntimeException("Cannot create new process $cmdLine"); } list($stdin, $this->stdout, $this->stderr) = $pipes; @@ -105,12 +105,12 @@ public function waitForFinish() /** * @return string - * @throws RunTimeException + * @throws RuntimeException */ public function getOutput() { if (!$this->isFinished()) { - throw new RunTimeException("Cannot get output for running process"); + throw new RuntimeException("Cannot get output for running process"); } return $this->output; @@ -118,12 +118,12 @@ public function getOutput() /** * @return string - * @throws RunTimeException + * @throws RuntimeException */ public function getErrorOutput() { if (!$this->isFinished()) { - throw new RunTimeException("Cannot get error output for running process"); + throw new RuntimeException("Cannot get error output for running process"); } return $this->errorOutput; @@ -131,12 +131,12 @@ public function getErrorOutput() /** * @return int - * @throws RunTimeException + * @throws RuntimeException */ public function getStatusCode() { if (!$this->isFinished()) { - throw new RunTimeException("Cannot get status code for running process"); + throw new RuntimeException("Cannot get status code for running process"); } return $this->statusCode; @@ -144,7 +144,7 @@ public function getStatusCode() /** * @return bool - * @throws RunTimeException + * @throws RuntimeException */ public function isFail() { diff --git a/src/Process/SkipLintProcess.php b/src/Process/SkipLintProcess.php index 52f4e76..c60d233 100644 --- a/src/Process/SkipLintProcess.php +++ b/src/Process/SkipLintProcess.php @@ -1,7 +1,7 @@ writers[] = $writer; } /** - * @param $string + * @param string $string */ public function write($string) { diff --git a/src/NullWriter.php b/src/Writers/NullWriter.php similarity index 52% rename from src/NullWriter.php rename to src/Writers/NullWriter.php index 52e3a61..067d810 100644 --- a/src/NullWriter.php +++ b/src/Writers/NullWriter.php @@ -1,7 +1,7 @@ getManager($settings); Assert::exception(function () use ($manager, $settings) { $manager->run($settings); - }, 'JakubOnderka\PhpParallelLint\NotExistsPathException'); + }, '\PhpParallelLint\PhpParallelLint\Exceptions\NotExistsPathException'); } public function testFilesNotFound() @@ -31,7 +31,7 @@ class ManagerRunTest extends Tester\TestCase $manager = $this->getManager($settings); Assert::exception(function () use ($manager, $settings) { $manager->run($settings); - }, 'JakubOnderka\PhpParallelLint\Exception', 'No file found to check.'); + }, '\PhpParallelLint\PhpParallelLint\Exceptions\ParallelLintException', 'No file found to check.'); } public function testSuccess() @@ -117,7 +117,7 @@ class ManagerRunTest extends Tester\TestCase } /** - * @return JakubOnderka\PhpParallelLint\Settings + * @return PhpParallelLint\PhpParallelLint\Settings */ private function prepareSettings() { diff --git a/tests/Output.phpt b/tests/Output.phpt index 0e227f6..7711da7 100644 --- a/tests/Output.phpt +++ b/tests/Output.phpt @@ -6,12 +6,13 @@ require __DIR__ . '/../vendor/autoload.php'; -use JakubOnderka\PhpParallelLint\ErrorFormatter; -use JakubOnderka\PhpParallelLint\GitLabOutput; -use JakubOnderka\PhpParallelLint\CheckstyleOutput; -use JakubOnderka\PhpParallelLint\IWriter; -use JakubOnderka\PhpParallelLint\Result; -use JakubOnderka\PhpParallelLint\SyntaxError; +use PhpParallelLint\PhpParallelLint\ErrorFormatter; +use PhpParallelLint\PhpParallelLint\Errors\ParallelLintError; +use PhpParallelLint\PhpParallelLint\Errors\SyntaxError; +use PhpParallelLint\PhpParallelLint\Outputs\CheckstyleOutput; +use PhpParallelLint\PhpParallelLint\Outputs\GitLabOutput; +use PhpParallelLint\PhpParallelLint\Result; +use PhpParallelLint\PhpParallelLint\Writers\WriterInterface; use Tester\Assert; class OutputTest extends Tester\TestCase @@ -50,7 +51,7 @@ class OutputTest extends Tester\TestCase public function testCheckstyleOutput() { $errors = array( - new JakubOnderka\PhpParallelLint\SyntaxError( + new SyntaxError( 'sample.php', 'Parse error: syntax error, unexpected \'"\' in ./sample.php on line 3' ), @@ -82,20 +83,20 @@ class OutputTest extends Tester\TestCase ), array( 'errors' => array( - new JakubOnderka\PhpParallelLint\Error('foo/bar.php', "PHP Parse error: syntax error, unexpected ';'") + new ParallelLintError('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 ';'") + new ParallelLintError('foo/bar.php', "PHP Parse error: syntax error, unexpected ';'") ) ), ); } } -class TestWriter implements IWriter +class TestWriter implements WriterInterface { /** @var string */ protected $logs = ""; diff --git a/tests/ParallelLint.lint.phpt b/tests/ParallelLint.lint.phpt index 4ed584c..24d1a4a 100644 --- a/tests/ParallelLint.lint.phpt +++ b/tests/ParallelLint.lint.phpt @@ -6,7 +6,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use JakubOnderka\PhpParallelLint\ParallelLint; +use PhpParallelLint\PhpParallelLint\ParallelLint; use Tester\Assert; class ParallelLintLintTest extends Tester\TestCase @@ -130,7 +130,7 @@ class ParallelLintLintTest extends Tester\TestCase private function getPhpExecutable() { - return \JakubOnderka\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); + return \PhpParallelLint\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); } } diff --git a/tests/Settings.parseArguments.phpt b/tests/Settings.parseArguments.phpt index a669195..5c2ba98 100644 --- a/tests/Settings.parseArguments.phpt +++ b/tests/Settings.parseArguments.phpt @@ -6,7 +6,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use JakubOnderka\PhpParallelLint\Settings; +use PhpParallelLint\PhpParallelLint\Settings; use Tester\Assert; class SettingsParseArgumentsTest extends Tester\TestCase diff --git a/tests/SkipLintProcess.phpt b/tests/SkipLintProcess.phpt index fa4fe85..e50054c 100644 --- a/tests/SkipLintProcess.phpt +++ b/tests/SkipLintProcess.phpt @@ -21,8 +21,8 @@ class SkipLintProcessTest extends Tester\TestCase $filesToCheck = array_merge($filesToCheck, $filesToCheck); } - $phpExecutable = \JakubOnderka\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); - $process = new \JakubOnderka\PhpParallelLint\Process\SkipLintProcess($phpExecutable, $filesToCheck); + $phpExecutable = \PhpParallelLint\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); + $process = new \PhpParallelLint\PhpParallelLint\Process\SkipLintProcess($phpExecutable, $filesToCheck); while (!$process->isFinished()) { usleep(100); diff --git a/tests/SyntaxError.normalizeMessage.phpt b/tests/SyntaxError.normalizeMessage.phpt index 62dc636..94e86db 100644 --- a/tests/SyntaxError.normalizeMessage.phpt +++ b/tests/SyntaxError.normalizeMessage.phpt @@ -6,7 +6,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use JakubOnderka\PhpParallelLint\SyntaxError; +use PhpParallelLint\PhpParallelLint\Errors\SyntaxError; use Tester\Assert; class SyntaxErrorNormalizeMessageTest extends Tester\TestCase From c765f9e294eca0fab73366af348e4bdead8958ff Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 19 Feb 2022 06:51:37 +0100 Subject: [PATCH 3/5] Change namespace prefix to PHP_Parallel_Lint ... to be in line with the other repos in the organisation. --- composer.json | 2 +- doc/syntax-error-callback.md | 6 ++-- parallel-lint | 2 +- src/Application.php | 6 ++-- src/Blame.php | 2 +- src/Contracts/SyntaxErrorCallback.php | 4 +-- src/ErrorFormatter.php | 6 ++-- src/Errors/ParallelLintError.php | 2 +- src/Errors/SyntaxError.php | 4 +-- src/Exceptions/InvalidArgumentException.php | 2 +- src/Exceptions/NotExistsClassException.php | 2 +- src/Exceptions/NotExistsPathException.php | 2 +- .../NotImplementCallbackException.php | 2 +- src/Exceptions/ParallelLintException.php | 2 +- src/Exceptions/RuntimeException.php | 2 +- src/Iterators/ArrayIterator.php | 2 +- .../RecursiveDirectoryFilterIterator.php | 2 +- src/Manager.php | 36 +++++++++---------- src/Outputs/CheckstyleOutput.php | 10 +++--- src/Outputs/GitLabOutput.php | 12 +++---- src/Outputs/JsonOutput.php | 8 ++--- src/Outputs/OutputInterface.php | 8 ++--- src/Outputs/TextOutput.php | 8 ++--- src/Outputs/TextOutputColored.php | 6 ++-- src/ParallelLint.php | 16 ++++----- src/Process/GitBlameProcess.php | 4 +-- src/Process/LintProcess.php | 6 ++-- src/Process/PhpExecutable.php | 4 +-- src/Process/PhpProcess.php | 4 +-- src/Process/Process.php | 4 +-- src/Process/SkipLintProcess.php | 4 +-- src/Result.php | 6 ++-- src/Settings.php | 6 ++-- src/Writers/ConsoleWriter.php | 2 +- src/Writers/FileWriter.php | 2 +- src/Writers/MultipleWriter.php | 2 +- src/Writers/NullWriter.php | 2 +- src/Writers/WriterInterface.php | 2 +- tests/Manager.run.phpt | 14 ++++---- tests/Output.phpt | 14 ++++---- tests/ParallelLint.lint.phpt | 4 +-- tests/Settings.parseArguments.phpt | 2 +- tests/SkipLintProcess.phpt | 4 +-- tests/SyntaxError.normalizeMessage.phpt | 2 +- 44 files changed, 121 insertions(+), 121 deletions(-) diff --git a/composer.json b/composer.json index 8755a07..b07a0cb 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ }, "autoload": { "psr-4": { - "PhpParallelLint\\PhpParallelLint\\": "src/" + "PHP_Parallel_Lint\\PhpParallelLint\\": "src/" } }, "autoload-dev": { diff --git a/doc/syntax-error-callback.md b/doc/syntax-error-callback.md index 89c980f..153ba24 100644 --- a/doc/syntax-error-callback.md +++ b/doc/syntax-error-callback.md @@ -1,7 +1,7 @@ # Syntax Error Callback 1. Set a path to a file with custom error callback to `--syntax-error-callback` option. -1. Create a class implementing `PhpParallelLint\PhpParallelLint\Contracts\SyntaxErrorCallback` interface. File with the class must have the same name as the class inside. +1. Create a class implementing `PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback` interface. File with the class must have the same name as the class inside. 1. Modify error before it is printed to the output. ## Example configuration @@ -11,8 +11,8 @@ The content should look like: ```php -use PhpParallelLint\PhpParallelLint\Contracts\SyntaxErrorCallback; -use PhpParallelLint\PhpParallelLint\Errors\SyntaxError; +use PHP_Parallel_Lint\PhpParallelLint\Contracts\SyntaxErrorCallback; +use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError; class MyCustomErrorHandler implements SyntaxErrorCallback { /** diff --git a/parallel-lint b/parallel-lint index 0100c93..b6bb513 100755 --- a/parallel-lint +++ b/parallel-lint @@ -70,5 +70,5 @@ if (!$loaded) { require_once __DIR__ . '/src/polyfill.php'; -$app = new PhpParallelLint\PhpParallelLint\Application(); +$app = new PHP_Parallel_Lint\PhpParallelLint\Application(); exit($app->run()); diff --git a/src/Application.php b/src/Application.php index 8bb0ee1..bb24e26 100644 --- a/src/Application.php +++ b/src/Application.php @@ -1,9 +1,9 @@ getManager($settings); Assert::exception(function () use ($manager, $settings) { $manager->run($settings); - }, '\PhpParallelLint\PhpParallelLint\Exceptions\NotExistsPathException'); + }, '\PHP_Parallel_Lint\PhpParallelLint\Exceptions\NotExistsPathException'); } public function testFilesNotFound() @@ -31,7 +31,7 @@ class ManagerRunTest extends Tester\TestCase $manager = $this->getManager($settings); Assert::exception(function () use ($manager, $settings) { $manager->run($settings); - }, '\PhpParallelLint\PhpParallelLint\Exceptions\ParallelLintException', 'No file found to check.'); + }, '\PHP_Parallel_Lint\PhpParallelLint\Exceptions\ParallelLintException', 'No file found to check.'); } public function testSuccess() @@ -117,7 +117,7 @@ class ManagerRunTest extends Tester\TestCase } /** - * @return PhpParallelLint\PhpParallelLint\Settings + * @return PHP_Parallel_Lint\PhpParallelLint\Settings */ private function prepareSettings() { diff --git a/tests/Output.phpt b/tests/Output.phpt index 7711da7..6bbb6cf 100644 --- a/tests/Output.phpt +++ b/tests/Output.phpt @@ -6,13 +6,13 @@ require __DIR__ . '/../vendor/autoload.php'; -use PhpParallelLint\PhpParallelLint\ErrorFormatter; -use PhpParallelLint\PhpParallelLint\Errors\ParallelLintError; -use PhpParallelLint\PhpParallelLint\Errors\SyntaxError; -use PhpParallelLint\PhpParallelLint\Outputs\CheckstyleOutput; -use PhpParallelLint\PhpParallelLint\Outputs\GitLabOutput; -use PhpParallelLint\PhpParallelLint\Result; -use PhpParallelLint\PhpParallelLint\Writers\WriterInterface; +use PHP_Parallel_Lint\PhpParallelLint\ErrorFormatter; +use PHP_Parallel_Lint\PhpParallelLint\Errors\ParallelLintError; +use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError; +use PHP_Parallel_Lint\PhpParallelLint\Outputs\CheckstyleOutput; +use PHP_Parallel_Lint\PhpParallelLint\Outputs\GitLabOutput; +use PHP_Parallel_Lint\PhpParallelLint\Result; +use PHP_Parallel_Lint\PhpParallelLint\Writers\WriterInterface; use Tester\Assert; class OutputTest extends Tester\TestCase diff --git a/tests/ParallelLint.lint.phpt b/tests/ParallelLint.lint.phpt index 24d1a4a..e1db87a 100644 --- a/tests/ParallelLint.lint.phpt +++ b/tests/ParallelLint.lint.phpt @@ -6,7 +6,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use PhpParallelLint\PhpParallelLint\ParallelLint; +use PHP_Parallel_Lint\PhpParallelLint\ParallelLint; use Tester\Assert; class ParallelLintLintTest extends Tester\TestCase @@ -130,7 +130,7 @@ class ParallelLintLintTest extends Tester\TestCase private function getPhpExecutable() { - return \PhpParallelLint\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); + return \PHP_Parallel_Lint\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); } } diff --git a/tests/Settings.parseArguments.phpt b/tests/Settings.parseArguments.phpt index 5c2ba98..e6b2612 100644 --- a/tests/Settings.parseArguments.phpt +++ b/tests/Settings.parseArguments.phpt @@ -6,7 +6,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use PhpParallelLint\PhpParallelLint\Settings; +use PHP_Parallel_Lint\PhpParallelLint\Settings; use Tester\Assert; class SettingsParseArgumentsTest extends Tester\TestCase diff --git a/tests/SkipLintProcess.phpt b/tests/SkipLintProcess.phpt index e50054c..39aa232 100644 --- a/tests/SkipLintProcess.phpt +++ b/tests/SkipLintProcess.phpt @@ -21,8 +21,8 @@ class SkipLintProcessTest extends Tester\TestCase $filesToCheck = array_merge($filesToCheck, $filesToCheck); } - $phpExecutable = \PhpParallelLint\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); - $process = new \PhpParallelLint\PhpParallelLint\Process\SkipLintProcess($phpExecutable, $filesToCheck); + $phpExecutable = \PHP_Parallel_Lint\PhpParallelLint\Process\PhpExecutable::getPhpExecutable('php'); + $process = new \PHP_Parallel_Lint\PhpParallelLint\Process\SkipLintProcess($phpExecutable, $filesToCheck); while (!$process->isFinished()) { usleep(100); diff --git a/tests/SyntaxError.normalizeMessage.phpt b/tests/SyntaxError.normalizeMessage.phpt index 94e86db..bb2f87b 100644 --- a/tests/SyntaxError.normalizeMessage.phpt +++ b/tests/SyntaxError.normalizeMessage.phpt @@ -6,7 +6,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use PhpParallelLint\PhpParallelLint\Errors\SyntaxError; +use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError; use Tester\Assert; class SyntaxErrorNormalizeMessageTest extends Tester\TestCase From 50609f4f7113a1625a75bb772cc78b0804a0d85b Mon Sep 17 00:00:00 2001 From: Roelof Roos Date: Mon, 22 Mar 2021 22:23:26 +0100 Subject: [PATCH 4/5] Rename some exceptions to be more self-explanatory --- ...n.php => CallbackNotImplementedException.php} | 2 +- ...sException.php => ClassNotFoundException.php} | 2 +- ...thException.php => PathNotFoundException.php} | 2 +- src/Manager.php | 16 ++++++++-------- tests/Manager.run.phpt | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename src/Exceptions/{NotImplementCallbackException.php => CallbackNotImplementedException.php} (84%) rename src/Exceptions/{NotExistsClassException.php => ClassNotFoundException.php} (89%) rename src/Exceptions/{NotExistsPathException.php => PathNotFoundException.php} (83%) diff --git a/src/Exceptions/NotImplementCallbackException.php b/src/Exceptions/CallbackNotImplementedException.php similarity index 84% rename from src/Exceptions/NotImplementCallbackException.php rename to src/Exceptions/CallbackNotImplementedException.php index ee3f95c..3d7ae00 100644 --- a/src/Exceptions/NotImplementCallbackException.php +++ b/src/Exceptions/CallbackNotImplementedException.php @@ -1,7 +1,7 @@ syntaxErrorCallbackFile); if ($fullFilePath === false) { - throw new NotExistsPathException($settings->syntaxErrorCallbackFile); + throw new PathNotFoundException($settings->syntaxErrorCallbackFile); } require_once $fullFilePath; $expectedClassName = basename($fullFilePath, '.php'); if (!class_exists($expectedClassName)) { - throw new NotExistsClassException($expectedClassName, $settings->syntaxErrorCallbackFile); + throw new ClassNotFoundException($expectedClassName, $settings->syntaxErrorCallbackFile); } $callbackInstance = new $expectedClassName; if (!($callbackInstance instanceof SyntaxErrorCallback)) { - throw new NotImplementCallbackException($expectedClassName); + throw new CallbackNotImplementedException($expectedClassName); } return $callbackInstance; diff --git a/tests/Manager.run.phpt b/tests/Manager.run.phpt index cabfb56..8382575 100644 --- a/tests/Manager.run.phpt +++ b/tests/Manager.run.phpt @@ -21,7 +21,7 @@ class ManagerRunTest extends Tester\TestCase $manager = $this->getManager($settings); Assert::exception(function () use ($manager, $settings) { $manager->run($settings); - }, '\PHP_Parallel_Lint\PhpParallelLint\Exceptions\NotExistsPathException'); + }, '\PHP_Parallel_Lint\PhpParallelLint\Exceptions\PathNotFoundException'); } public function testFilesNotFound() From b455c88eb5511f41c53f3cc976396f6635d6b7d8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 19 Feb 2022 12:00:48 +0100 Subject: [PATCH 5/5] Fix test runs on PHP 5.3 As the tests don't have a dedicated bootstrap file and loading of the `polyfill.php` file is no longer handled via the classmap, a `require` is needed in the test files. --- tests/Manager.run.phpt | 1 + tests/Output.phpt | 1 + tests/ParallelLint.lint.phpt | 1 + tests/Settings.parseArguments.phpt | 1 + tests/SkipLintProcess.phpt | 1 + tests/SyntaxError.normalizeMessage.phpt | 1 + 6 files changed, 6 insertions(+) diff --git a/tests/Manager.run.phpt b/tests/Manager.run.phpt index 8382575..5b21bb4 100644 --- a/tests/Manager.run.phpt +++ b/tests/Manager.run.phpt @@ -4,6 +4,7 @@ * @testCase */ +require_once __DIR__ . '/../src/polyfill.php'; require __DIR__ . '/../vendor/autoload.php'; use PHP_Parallel_Lint\PhpParallelLint\Manager; diff --git a/tests/Output.phpt b/tests/Output.phpt index 6bbb6cf..9a3767a 100644 --- a/tests/Output.phpt +++ b/tests/Output.phpt @@ -4,6 +4,7 @@ * @testCase */ +require_once __DIR__ . '/../src/polyfill.php'; require __DIR__ . '/../vendor/autoload.php'; use PHP_Parallel_Lint\PhpParallelLint\ErrorFormatter; diff --git a/tests/ParallelLint.lint.phpt b/tests/ParallelLint.lint.phpt index e1db87a..b118d21 100644 --- a/tests/ParallelLint.lint.phpt +++ b/tests/ParallelLint.lint.phpt @@ -4,6 +4,7 @@ * @testCase */ +require_once __DIR__ . '/../src/polyfill.php'; require __DIR__ . '/../vendor/autoload.php'; use PHP_Parallel_Lint\PhpParallelLint\ParallelLint; diff --git a/tests/Settings.parseArguments.phpt b/tests/Settings.parseArguments.phpt index e6b2612..39e01e2 100644 --- a/tests/Settings.parseArguments.phpt +++ b/tests/Settings.parseArguments.phpt @@ -4,6 +4,7 @@ * @testCase */ +require_once __DIR__ . '/../src/polyfill.php'; require __DIR__ . '/../vendor/autoload.php'; use PHP_Parallel_Lint\PhpParallelLint\Settings; diff --git a/tests/SkipLintProcess.phpt b/tests/SkipLintProcess.phpt index 39aa232..3078c3e 100644 --- a/tests/SkipLintProcess.phpt +++ b/tests/SkipLintProcess.phpt @@ -4,6 +4,7 @@ * @testCase */ +require_once __DIR__ . '/../src/polyfill.php'; require __DIR__ . '/../vendor/autoload.php'; use Tester\Assert; diff --git a/tests/SyntaxError.normalizeMessage.phpt b/tests/SyntaxError.normalizeMessage.phpt index bb2f87b..bb17a8d 100644 --- a/tests/SyntaxError.normalizeMessage.phpt +++ b/tests/SyntaxError.normalizeMessage.phpt @@ -4,6 +4,7 @@ * @testCase */ +require_once __DIR__ . '/../src/polyfill.php'; require __DIR__ . '/../vendor/autoload.php'; use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;