diff --git a/LibHooks/lib/PreCommit/Validator/AbstractValidator.php b/LibHooks/lib/PreCommit/Validator/AbstractValidator.php index a052687..d800b9f 100644 --- a/LibHooks/lib/PreCommit/Validator/AbstractValidator.php +++ b/LibHooks/lib/PreCommit/Validator/AbstractValidator.php @@ -33,6 +33,10 @@ abstract class AbstractValidator protected $errorMessages = array(); /** + * Init options + * + * Init error collector + * * @param array $options * @throws Exception */ @@ -65,7 +69,7 @@ abstract public function validate($content, $file); * @param int $line * @return $this */ - protected function _addError($file, $type, $value = null, $line = null) + protected function addError($file, $type, $value = null, $line = null) { $this->errorCollector->addError($file, $type, $this->errorMessages[$type], $value, $line); } diff --git a/LibHooks/lib/PreCommit/Validator/CodingStandard.php b/LibHooks/lib/PreCommit/Validator/CodingStandard.php index d23395b..845d570 100644 --- a/LibHooks/lib/PreCommit/Validator/CodingStandard.php +++ b/LibHooks/lib/PreCommit/Validator/CodingStandard.php @@ -93,7 +93,7 @@ protected function validateGaps($content, $file) preg_match_all('/\n\n\n/', $content, $match); if ($match[0]) { - $this->_addError($file, self::CODE_PHP_GAPS, count($match[0])); + $this->addError($file, self::CODE_PHP_GAPS, count($match[0])); } preg_match_all('/(\{|\()\n\n.*|.*\n\n[ ]*(\}|\))/', $content, $match); @@ -109,7 +109,7 @@ protected function validateGaps($content, $file) sort($lines); //endregion - $this->_addError($file, self::CODE_PHP_BRACKET_GAPS, count($match[0]), $lines); + $this->addError($file, self::CODE_PHP_BRACKET_GAPS, count($match[0]), $lines); } return $this; @@ -156,22 +156,22 @@ protected function validateCodeStyleByLines($content, $file) // operator & && must be wrapped with spaces || preg_match('/[^\(\s&]&{1,2}|&{1,2}[^\s&$]/i', $str) ) { - $this->_addError($file, self::CODE_PHP_OPERATOR_SPACES_MISSED, $currentString, $line); + $this->addError($file, self::CODE_PHP_OPERATOR_SPACES_MISSED, $currentString, $line); } //checking for an assignment in a condition if (preg_match('~if\s*\((.*?)\)\s*[{:]~s', $str, $a)) { if (preg_match('~\$[^= ]+ ?= ?[^=]~', $a[1])) { - $this->_addError($file, self::CODE_PHP_CONDITION_ASSIGNMENT, $currentString, $line); + $this->addError($file, self::CODE_PHP_CONDITION_ASSIGNMENT, $currentString, $line); } } if (preg_match('/(?:[,\(\)\{\}=]\s{2,}|\w\s{2,}[\(\)\{\}]|\s+[,]|\S\s+[)]|[(]\s+)/i', $str)) { - $this->_addError($file, self::CODE_PHP_REDUNDANT_SPACES, $currentString, $line); + $this->addError($file, self::CODE_PHP_REDUNDANT_SPACES, $currentString, $line); } if (strlen($str) > 120) { - $this->_addError($file, self::CODE_PHP_LINE_EXCEEDS, null, $line); + $this->addError($file, self::CODE_PHP_LINE_EXCEEDS, null, $line); } $operators = 'elseif|else if|else|if|switch|foreach|for|while|do'; @@ -184,36 +184,36 @@ protected function validateCodeStyleByLines($content, $file) if (preg_match('/^[^A-z0-9\>\$]*(try|do)[^A-z0-9-\$]*$/', trim($str)) && trim($str) !== $b[1].' {' ) { - $this->_addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); + $this->addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); } } elseif ($b[1] == 'while') { if (substr(trim($str), -1) == ';' && !preg_match('/^\s+\} while \(.*\);$/', $str) || substr(trim($str), -1) != ';' && !preg_match('/^\s+while \(.*\) {$/', $str) ) { - $this->_addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); + $this->addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); } } elseif ($b[1] == 'else') { if (!preg_match('/\s*} else {$/i', $str)) { - $this->_addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); + $this->addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); } } elseif (substr(trim($b[0]), -3) != ') {') { $bracketRight = substr_count($b[0], ')'); $bracketLeft = substr_count($b[0], '('); if ($bracketLeft >= 1 && $bracketLeft == $bracketRight) { - $this->_addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); + $this->addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); } } elseif (substr(ltrim($b[0], ' }'), strlen($b[1]), 1) != ' ') { //check right space after construct - $this->_addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); + $this->addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); } } //check try..catch if (preg_match('/[^A-z]try[^A-z]/i', $str) && !preg_match('/^(\s+try \{)$/i', $str, $b)) { - $this->_addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); + $this->addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); } elseif (preg_match('/[^A-z]catch/i', $str) && !preg_match('/^\s*(\} catch \([A-z0-9_\\]+ \$[A-z0-9_]+\) \{)$/', $str, $m) ) { - $this->_addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); + $this->addError($file, self::CODE_PHP_SPACE_BRACKET, $currentString, $line); } //check function naming and scope @@ -222,17 +222,17 @@ protected function validateCodeStyleByLines($content, $file) if (preg_match('/^\s*(static )?public /', $str) && !preg_match('/public (static )?function ([a-z]{2}|__[a-z]{2})/', $str) ) { - $this->_addError($file, self::CODE_PHP_PUBLIC_METHOD_NAMING_INVALID, $currentString, $line); + $this->addError($file, self::CODE_PHP_PUBLIC_METHOD_NAMING_INVALID, $currentString, $line); } elseif ($this->useUnderScoreInProtected() && preg_match('/^\s*(static )?(protected|private) /', $str) && !preg_match('/(protected|private) (static )?function _[a-z]{2}/', $str) ) { - $this->_addError($file, self::CODE_PHP_PROTECTED_METHOD_NAMING_INVALID, $currentString, $line); + $this->addError($file, self::CODE_PHP_PROTECTED_METHOD_NAMING_INVALID, $currentString, $line); } elseif (!$this->useUnderScoreInProtected() && preg_match('/^\s*(static )?(protected|private) /', $str) && !preg_match('/(protected|private) (static )?function [a-z]{2}/', $str) ) { - $this->_addError( + $this->addError( $file, self::CODE_PHP_PROTECTED_METHOD_NAMING_INVALID_NO_UNDERSCORE, $currentString, @@ -241,7 +241,7 @@ protected function validateCodeStyleByLines($content, $file) } } if (!preg_match('/(protected|private|public) (static )?function/', $str)) { - $this->_addError($file, self::CODE_PHP_METHOD_SCOPE, $currentString, $line); + $this->addError($file, self::CODE_PHP_METHOD_SCOPE, $currentString, $line); } } @@ -261,7 +261,7 @@ protected function validateCodeStyleByLines($content, $file) } if ($vars) { $values = array('value' => $currentString, 'vars' => implode(',', $vars)); - $this->_addError($file, self::CODE_PHP_UNDERSCORE_IN_VAR, $values, $line); + $this->addError($file, self::CODE_PHP_UNDERSCORE_IN_VAR, $values, $line); } } } diff --git a/LibHooks/lib/PreCommit/Validator/CodingStandardMagento.php b/LibHooks/lib/PreCommit/Validator/CodingStandardMagento.php index 0d9acbe..8010830 100644 --- a/LibHooks/lib/PreCommit/Validator/CodingStandardMagento.php +++ b/LibHooks/lib/PreCommit/Validator/CodingStandardMagento.php @@ -45,7 +45,7 @@ public function validate($content, $file) $currentString = trim($originalArr[$line - 1]); //check using Mage::throwException(); if (false !== strpos($str, 'Mage::throwException(')) { - $this->_addError($file, self::CODE_PHP_DEPRECATED_THROW_EXCEPTION, $currentString, $line); + $this->addError($file, self::CODE_PHP_DEPRECATED_THROW_EXCEPTION, $currentString, $line); } } diff --git a/LibHooks/lib/PreCommit/Validator/CodingStandardPhtml.php b/LibHooks/lib/PreCommit/Validator/CodingStandardPhtml.php index 8f7ed59..1f0ef45 100644 --- a/LibHooks/lib/PreCommit/Validator/CodingStandardPhtml.php +++ b/LibHooks/lib/PreCommit/Validator/CodingStandardPhtml.php @@ -65,7 +65,7 @@ protected function validateGaps($content, $file) preg_match_all('/\n\n\n/', $content, $match); if ($match[0]) { - $this->_addError($file, self::CODE_PHTML_GAPS, count($match[0])); + $this->addError($file, self::CODE_PHTML_GAPS, count($match[0])); } return $this; @@ -125,7 +125,7 @@ protected function validateStringAlternativeSyntaxUsage($file, $str, $line) && substr_count($str, '(') === substr_count($str, ')') //ignore multi-line conditions && !preg_match('/[^A-z0-9]+(?:'.$operators.').*?\).*?:/i', $b[0], $m) ) { - $this->_addError($file, self::CODE_PHTML_ALTERNATIVE_SYNTAX, $str, $line); + $this->addError($file, self::CODE_PHTML_ALTERNATIVE_SYNTAX, $str, $line); } return $this; @@ -150,7 +150,7 @@ protected function validateStringNoUnderscoreInVariableName($file, $str, $line) } if ($vars) { $values = array('value' => $str, 'vars' => implode(',', $vars)); - $this->_addError($file, self::CODE_PHTML_UNDERSCORE_IN_VAR, $values, $line); + $this->addError($file, self::CODE_PHTML_UNDERSCORE_IN_VAR, $values, $line); } } @@ -168,7 +168,7 @@ protected function validateStringNoUnderscoreInVariableName($file, $str, $line) protected function validateStringNoProtectedMethodUsage($file, $str, $line) { if (preg_match('/\$this-\>_[^_]/', $str)) { - $this->_addError($file, self::CODE_PHTML_PROTECTED_METHOD, $str, $line); + $this->addError($file, self::CODE_PHTML_PROTECTED_METHOD, $str, $line); } return $this; @@ -185,7 +185,7 @@ protected function validateStringNoProtectedMethodUsage($file, $str, $line) protected function validateStringNoClassesUsage($file, $str, $line) { if (preg_match('/[A-z_]{3,}\:\:[A-z_]/', $str)) { - $this->_addError($file, self::CODE_PHTML_CLASS, $str, $line); + $this->addError($file, self::CODE_PHTML_CLASS, $str, $line); } return $this; diff --git a/LibHooks/lib/PreCommit/Validator/CommitMsg.php b/LibHooks/lib/PreCommit/Validator/CommitMsg.php index fbba9b0..d95686a 100644 --- a/LibHooks/lib/PreCommit/Validator/CommitMsg.php +++ b/LibHooks/lib/PreCommit/Validator/CommitMsg.php @@ -79,7 +79,7 @@ public function __construct(array $options) public function validate($message, $file) { if (!$this->matchMessage($message)) { - $this->_addError('Commit Message', self::CODE_BAD_COMMIT_MESSAGE, $message->head); + $this->addError('Commit Message', self::CODE_BAD_COMMIT_MESSAGE, $message->head); } return !$this->errorCollector->hasErrors(); @@ -158,7 +158,7 @@ protected function getInterpreterResult($message, array $config) continue; } if (!isset($result[$name]) || !$result[$name]) { - $this->_addError('Commit Message', self::CODE_VERB_INCORRECT, $name); + $this->addError('Commit Message', self::CODE_VERB_INCORRECT, $name); return false; } @@ -172,7 +172,7 @@ protected function getInterpreterResult($message, array $config) //find verb key $key = array_search($message->verb, $this->getVerbs()); if (false === $key) { - $this->_addError('Commit Message', self::CODE_VERB_NOT_FOUND, $message->verb); + $this->addError('Commit Message', self::CODE_VERB_NOT_FOUND, $message->verb); return false; } @@ -180,7 +180,7 @@ protected function getInterpreterResult($message, array $config) //check allowed verb by issue type if (!$this->errorCollector->hasErrors()) { if (!$message->issue->getType()) { - $this->_addError( + $this->addError( 'Commit Message', self::CODE_ISSUE_TYPE_INCORRECT, $message->issue->getOriginalType() @@ -191,7 +191,7 @@ protected function getInterpreterResult($message, array $config) //it's cannot be processed if issue type is not valid $allowed = $this->getAllowedVerbs($message->issue->getType()); if (!isset($allowed[$key]) || !$allowed[$key]) { - $this->_addError('Commit Message', self::CODE_VERB_INCORRECT, $message->verb); + $this->addError('Commit Message', self::CODE_VERB_INCORRECT, $message->verb); return false; } diff --git a/LibHooks/lib/PreCommit/Validator/FileFilter.php b/LibHooks/lib/PreCommit/Validator/FileFilter.php index ac1e996..1bd84e2 100644 --- a/LibHooks/lib/PreCommit/Validator/FileFilter.php +++ b/LibHooks/lib/PreCommit/Validator/FileFilter.php @@ -62,23 +62,23 @@ public function validate($content, $file) return false; } - if ($this->_isFileAllowed($file)) { + if ($this->isFileAllowed($file)) { //file is allowed to edit, no need to check protection - return !$this->_isFileSkipped($file); + return !$this->isFileSkipped($file); } - return !$this->_isFileProtected($file) && !$this->_isFileSkipped($file); + return !$this->isFileProtected($file) && !$this->isFileSkipped($file); } /** * Check file from ignore list * - * @param $file + * @param string $file * @return bool */ - protected function _isFileAllowed($file) + protected function isFileAllowed($file) { - if ($this->_isFileAllowedByPath($file)) { + if ($this->isFileAllowedByPath($file)) { return true; } $list = Config::getInstance()->getMultiNode(self::XPATH_ALLOW_FILES); @@ -97,9 +97,9 @@ protected function _isFileAllowed($file) * @param string $file * @return bool */ - protected function _isFileSkipped($file) + protected function isFileSkipped($file) { - if ($this->_isFileSkippedByPath($file)) { + if ($this->isFileSkippedByPath($file)) { return true; } @@ -125,18 +125,18 @@ protected function _isFileSkipped($file) /** * Check file from ignore list * - * @param $file + * @param string $file * @return bool */ - protected function _isFileProtected($file) + protected function isFileProtected($file) { - if ($this->_isFileProtectedByPath($file)) { + if ($this->isFileProtectedByPath($file)) { return true; } $list = Config::getInstance()->getMultiNode(self::XPATH_PROTECT_FILES); foreach ($list as $item) { if (strpos($file, $item) === 0) { - $this->_addError($file, self::PROTECTED_FILE, $item); + $this->addError($file, self::PROTECTED_FILE, $item); return true; } @@ -148,10 +148,10 @@ protected function _isFileProtected($file) /** * Check if file in allowed path * - * @param $file + * @param string $file * @return bool */ - protected function _isFileAllowedByPath($file) + protected function isFileAllowedByPath($file) { $list = Config::getInstance()->getMultiNode(self::XPATH_ALLOW_PATHS); foreach ($list as $item) { @@ -169,7 +169,7 @@ protected function _isFileAllowedByPath($file) * @param string $file * @return bool */ - protected function _isFileSkippedByPath($file) + protected function isFileSkippedByPath($file) { $list = Config::getInstance()->getMultiNode(self::XPATH_SKIP_PATHS); foreach ($list as $item) { @@ -184,15 +184,15 @@ protected function _isFileSkippedByPath($file) /** * Check file from ignore list * - * @param $file + * @param string $file * @return bool */ - protected function _isFileProtectedByPath($file) + protected function isFileProtectedByPath($file) { $list = Config::getInstance()->getMultiNode(self::XPATH_PROTECT_PATHS); foreach ($list as $item) { if (strpos($file, (string) $item) === 0) { - $this->_addError($file, self::PROTECTED_PATH, $item); + $this->addError($file, self::PROTECTED_PATH, $item); return true; } diff --git a/LibHooks/lib/PreCommit/Validator/FileStyle.php b/LibHooks/lib/PreCommit/Validator/FileStyle.php index 1d1e225..33cffe8 100644 --- a/LibHooks/lib/PreCommit/Validator/FileStyle.php +++ b/LibHooks/lib/PreCommit/Validator/FileStyle.php @@ -62,7 +62,7 @@ protected function validateTabIndents($content, $file) //$line = count(explode("\n", $matches[0])); preg_match_all('~(\t)~s', $content, $tbMatches); - $this->_addError( + $this->addError( $file, self::CODE_TAB_CHAR, count($tbMatches[0]) @@ -81,7 +81,7 @@ protected function validateLineBreaks($content, $file) { //checking for windows line breaks if (preg_match_all('~(\r\n)~s', $content, $lnMatches)) { - $this->_addError( + $this->addError( $file, self::CODE_WIN_LINE_BREAK, count($lnMatches[0]) @@ -101,7 +101,7 @@ protected function validateLineBreaks($content, $file) protected function validateBom($content, $file) { if (substr($content, 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf)) { - $this->_addError($file, self::CODE_FILE_BOM); + $this->addError($file, self::CODE_FILE_BOM); } return $this; diff --git a/LibHooks/lib/PreCommit/Validator/IssueStatus.php b/LibHooks/lib/PreCommit/Validator/IssueStatus.php index bf382a5..6b27da1 100644 --- a/LibHooks/lib/PreCommit/Validator/IssueStatus.php +++ b/LibHooks/lib/PreCommit/Validator/IssueStatus.php @@ -39,7 +39,7 @@ public function __construct(array $options = array()) { parent::__construct($options); - $this->_type = $this->_getConfig()->getNode('hooks/commit-msg/message/type'); + $this->_type = $this->getConfig()->getNode('hooks/commit-msg/message/type'); if (!$this->_type) { throw new Exception('Type is not set.'); } @@ -55,9 +55,9 @@ public function __construct(array $options = array()) public function validate($message, $file) { if ($message->issue && $message->issue->getStatus() - && !$this->_isAllowed($message->issue->getStatus()) + && !$this->isAllowed($message->issue->getStatus()) ) { - $this->_addError('Commit Message', self::CODE_WRONG_ISSUE_STATUS, $message->issue->getStatus()); + $this->addError('Commit Message', self::CODE_WRONG_ISSUE_STATUS, $message->issue->getStatus()); } return !$this->errorCollector->hasErrors(); @@ -68,13 +68,13 @@ public function validate($message, $file) * * @return array */ - protected function _getStatuses() + protected function getStatuses() { - return (array) $this->_getConfig()->getNodeArray( - 'validators/IssueStatus/issue/status/'.$this->_getTrackerType().'/allowed/'.$this->_type + return (array) $this->getConfig()->getNodeArray( + 'validators/IssueStatus/issue/status/'.$this->getTrackerType().'/allowed/'.$this->_type ) - ?: (array) $this->_getConfig()->getNodeArray( - 'validators/IssueStatus/issue/status/'.$this->_getTrackerType().'/allowed/'.$this->_type + ?: (array) $this->getConfig()->getNodeArray( + 'validators/IssueStatus/issue/status/'.$this->getTrackerType().'/allowed/'.$this->_type ); } @@ -83,9 +83,9 @@ protected function _getStatuses() * * @return string */ - protected function _getTrackerType() + protected function getTrackerType() { - return (string) $this->_getConfig()->getNode('tracker/type'); + return (string) $this->getConfig()->getNode('tracker/type'); } /** @@ -93,7 +93,7 @@ protected function _getTrackerType() * * @return Config */ - protected function _getConfig() + protected function getConfig() { return Config::getInstance(); } @@ -104,9 +104,9 @@ protected function _getConfig() * @param string $status * @return bool */ - protected function _isAllowed($status) + protected function isAllowed($status) { - $allowedStatuses = $this->_getStatuses(); + $allowedStatuses = $this->getStatuses(); return isset($allowedStatuses[$status]) && $allowedStatuses[$status]; diff --git a/LibHooks/lib/PreCommit/Validator/IssueType.php b/LibHooks/lib/PreCommit/Validator/IssueType.php index 0ea191d..ad89aae 100644 --- a/LibHooks/lib/PreCommit/Validator/IssueType.php +++ b/LibHooks/lib/PreCommit/Validator/IssueType.php @@ -38,7 +38,7 @@ class IssueType extends AbstractValidator public function validate($message, $file) { if ($message->issue && !$message->issue->getType()) { - $this->_addError('Commit Message', self::CODE_WRONG_ISSUE_TYPE, $message->issue->getOriginalType()); + $this->addError('Commit Message', self::CODE_WRONG_ISSUE_TYPE, $message->issue->getOriginalType()); } return !$this->errorCollector->hasErrors(); diff --git a/LibHooks/lib/PreCommit/Validator/Magento/ModelEventFields.php b/LibHooks/lib/PreCommit/Validator/Magento/ModelEventFields.php index 720470e..abe298e 100644 --- a/LibHooks/lib/PreCommit/Validator/Magento/ModelEventFields.php +++ b/LibHooks/lib/PreCommit/Validator/Magento/ModelEventFields.php @@ -90,7 +90,7 @@ protected function isAbstractClass($content) protected function checkEventPrefix($content, $file) { if (!preg_match('/_eventPrefix[ ]+=[ ]/', $content)) { - $this->_addError($file, self::CODE_MODEL_MISSED_EVENT_PREFIX); + $this->addError($file, self::CODE_MODEL_MISSED_EVENT_PREFIX); } return $this; @@ -106,7 +106,7 @@ protected function checkEventPrefix($content, $file) protected function checkEventObject($content, $file) { if (!preg_match('/_eventObject[ ]+=[ ]/', $content)) { - $this->_addError($file, self::CODE_MODEL_MISSED_EVENT_OBJECT); + $this->addError($file, self::CODE_MODEL_MISSED_EVENT_OBJECT); } return $this; diff --git a/LibHooks/lib/PreCommit/Validator/ParentThis.php b/LibHooks/lib/PreCommit/Validator/ParentThis.php index 4e7627e..e82751d 100644 --- a/LibHooks/lib/PreCommit/Validator/ParentThis.php +++ b/LibHooks/lib/PreCommit/Validator/ParentThis.php @@ -75,7 +75,7 @@ protected function validateParentClassInReturn($parentClass, $content, $file) $regularClass = ltrim($parentClass, '\\'); //remove left "\" $regularClass = str_replace('\\', '\x5C', $regularClass); //set codes instead "\" if (preg_match('~ +\* @return +\x5C?'.$regularClass.'~', $content)) { - $this->_addError($file, self::CODE_PHP_RETURN_NOT_THIS, $parentClass, null); + $this->addError($file, self::CODE_PHP_RETURN_NOT_THIS, $parentClass, null); } return $this; diff --git a/LibHooks/lib/PreCommit/Validator/PhpClass.php b/LibHooks/lib/PreCommit/Validator/PhpClass.php index 757d57b..6db14dd 100644 --- a/LibHooks/lib/PreCommit/Validator/PhpClass.php +++ b/LibHooks/lib/PreCommit/Validator/PhpClass.php @@ -81,7 +81,7 @@ public function validate($content, $file) protected function validatePhpOpenedTag($content, $file) { if (0 !== strpos($content, '_addError($file, self::CODE_PHP_TAG); + $this->addError($file, self::CODE_PHP_TAG); } return $this; @@ -100,7 +100,7 @@ protected function validatePhpByInterpret($filePath, $file) exec($exe, $output, $code); if ($code != 0) { $value = trim(implode(" ", str_replace($filePath, $file, $output))); - $this->_addError( + $this->addError( $file, self::CODE_PHP_INTERPRET, array( diff --git a/LibHooks/lib/PreCommit/Validator/PhpDoc.php b/LibHooks/lib/PreCommit/Validator/PhpDoc.php index c7ceef6..52722ee 100644 --- a/LibHooks/lib/PreCommit/Validator/PhpDoc.php +++ b/LibHooks/lib/PreCommit/Validator/PhpDoc.php @@ -61,23 +61,23 @@ class PhpDoc extends AbstractValidator public function validate($content, $file) { //clean up group comments with nodes - $content = $this->_cleanGroupCommentedNodes($content); + $content = $this->cleanGroupCommentedNodes($content); $text = preg_split('/\x0A\x0D|\x0D\x0A|\x0A|\x0D/', $content); foreach ($text as $line => $str) { $line++; - $this->_validateEnterDescription($file, $str, $line); - $this->_validateUnknownType($file, $str, $line); + $this->validateEnterDescription($file, $str, $line); + $this->validateUnknownType($file, $str, $line); } - $this->_validateExistPhpDocsForClassItems($content, $file); - $this->_validateExistPhpDocForClass($content, $file); - $this->_validateExistPhpDocMessage($content, $file); - $this->_validateMissedGapAfterPhpDocMessage($content, $file); - $this->_validateExistPhpDocExtraGap($content, $file); - $this->_validateExistPhpDocVarEmptyType($content, $file); - $this->_validateExistPhpDocVarNull($content, $file); - $this->_validateSingleAsterisk($content, $file); + $this->validateExistPhpDocsForClassItems($content, $file); + $this->validateExistPhpDocForClass($content, $file); + $this->validateExistPhpDocMessage($content, $file); + $this->validateMissedGapAfterPhpDocMessage($content, $file); + $this->validateExistPhpDocExtraGap($content, $file); + $this->validateExistPhpDocVarEmptyType($content, $file); + $this->validateExistPhpDocVarNull($content, $file); + $this->validateSingleAsterisk($content, $file); return !$this->errorCollector->hasErrors(); } @@ -88,7 +88,7 @@ public function validate($content, $file) * @param string $content * @return string */ - protected function _cleanGroupCommentedNodes($content) + protected function cleanGroupCommentedNodes($content) { return preg_replace('/\s*\/\*\*\#\@\+(\s|\S)*?\/\*\*\#@\-\*\//', '', $content); } @@ -101,10 +101,10 @@ protected function _cleanGroupCommentedNodes($content) * @param string $line * @return $this */ - protected function _validateEnterDescription($file, $str, $line) + protected function validateEnterDescription($file, $str, $line) { if (preg_match('/\*\s*Enter '.'description here/i', $str)) { - $this->_addError($file, self::CODE_PHP_DOC_ENTER_DESCRIPTION, null, $line); + $this->addError($file, self::CODE_PHP_DOC_ENTER_DESCRIPTION, null, $line); } return $this; @@ -118,10 +118,10 @@ protected function _validateEnterDescription($file, $str, $line) * @param string $line * @return $this */ - protected function _validateUnknownType($file, $str, $line) + protected function validateUnknownType($file, $str, $line) { if (preg_match('/\*\x20\@.*?unknown_type/i', $str)) { - $this->_addError($file, self::CODE_PHP_DOC_UNKNOWN, null, $line); + $this->addError($file, self::CODE_PHP_DOC_UNKNOWN, null, $line); } return $this; @@ -134,17 +134,17 @@ protected function _validateUnknownType($file, $str, $line) * @param string $file * @return $this */ - protected function _validateExistPhpDocsForClassItems($content, $file) + protected function validateExistPhpDocsForClassItems($content, $file) { $reg = '/(?_addError( + $this->addError( $file, self::CODE_PHP_DOC_MISSED, $match, - $this->_findLines($match, $content, true) + $this->findLines($match, $content, true) ); } } @@ -159,11 +159,11 @@ protected function _validateExistPhpDocsForClassItems($content, $file) * @param string $file * @return $this */ - protected function _validateExistPhpDocForClass($content, $file) + protected function validateExistPhpDocForClass($content, $file) { if (preg_match_all('/(?_addError($file, self::CODE_PHP_DOC_MISSED, $match); + $this->addError($file, self::CODE_PHP_DOC_MISSED, $match); } } @@ -177,7 +177,7 @@ protected function _validateExistPhpDocForClass($content, $file) * @param string $file * @return $this */ - protected function _validateExistPhpDocMessage($content, $file) + protected function validateExistPhpDocMessage($content, $file) { if (preg_match_all( '/\x20+\/\*\*\x0D?\x0A\x20+\*([^ ][^A-Z]|\x20[^A-Z])(\s|\S)*?\*\//', @@ -201,12 +201,12 @@ protected function _validateExistPhpDocMessage($content, $file) $findings = array_unique($findings); $lines = array(); foreach ($findings as $find) { - $lines = array_merge($lines, $this->_findLines($find, $content)); + $lines = array_merge($lines, $this->findLines($find, $content)); } sort($lines); //endregion - $this->_addError($file, self::CODE_PHP_DOC_MESSAGE, null, $lines); + $this->addError($file, self::CODE_PHP_DOC_MESSAGE, null, $lines); } return $this; @@ -219,7 +219,7 @@ protected function _validateExistPhpDocMessage($content, $file) * @param string $file * @return $this */ - protected function _validateMissedGapAfterPhpDocMessage($content, $file) + protected function validateMissedGapAfterPhpDocMessage($content, $file) { if (preg_match_all( '/\x20+\* \w.*(?=\x0D?\x0A\x20+\*\x20@)/', @@ -227,7 +227,7 @@ protected function _validateMissedGapAfterPhpDocMessage($content, $file) $matches )) { foreach ($matches[0] as $match) { - $this->_addError($file, self::CODE_PHP_DOC_MISSED_GAP, $match); + $this->addError($file, self::CODE_PHP_DOC_MISSED_GAP, $match); } } @@ -241,15 +241,15 @@ protected function _validateMissedGapAfterPhpDocMessage($content, $file) * @param string $file * @return $this */ - protected function _validateExistPhpDocExtraGap($content, $file) + protected function validateExistPhpDocExtraGap($content, $file) { if (preg_match_all( '/\x0D?\x0A\x20+\*\x0D?\x0A\x20+\*(\x0D?\x0A|\/)/', $content, $matches )) { - $lines = $this->_findLines(rtrim($matches[0][0]), $content); - $this->_addError($file, self::CODE_PHP_DOC_EXTRA_GAP, count($matches[0]), $lines); + $lines = $this->findLines(rtrim($matches[0][0]), $content); + $this->addError($file, self::CODE_PHP_DOC_EXTRA_GAP, count($matches[0]), $lines); } return $this; @@ -262,7 +262,7 @@ protected function _validateExistPhpDocExtraGap($content, $file) * @param string $file * @return $this */ - protected function _validateExistPhpDocVarEmptyType($content, $file) + protected function validateExistPhpDocVarEmptyType($content, $file) { if (preg_match_all( '/\x0D?\x0A\x20+\*\x20(@(param|var)((\x20+\$.+)|(\x0D?\x0A)))/', @@ -271,9 +271,9 @@ protected function _validateExistPhpDocVarEmptyType($content, $file) )) { $lines = array(); foreach ($matches[0] as $match) { - $lines[] = $this->_findLines(trim($match), $content, true); + $lines[] = $this->findLines(trim($match), $content, true); } - $this->_addError($file, self::CODE_PHP_DOC_VAR_EMPTY, count($matches[0]), $lines); + $this->addError($file, self::CODE_PHP_DOC_VAR_EMPTY, count($matches[0]), $lines); } return $this; @@ -286,7 +286,7 @@ protected function _validateExistPhpDocVarEmptyType($content, $file) * @param string $file * @return $this */ - protected function _validateExistPhpDocVarNull($content, $file) + protected function validateExistPhpDocVarNull($content, $file) { if (preg_match_all( '/\x0D?\x0A\x20+\*\x20@(param|var)\x20(null|NULL)(\x0D?\x0A|\x20)/', @@ -301,10 +301,10 @@ protected function _validateExistPhpDocVarNull($content, $file) ' * @param null'."\n", ); foreach ($findings as $find) { - $lines = array_merge($lines, $this->_findLines($find, $content)); + $lines = array_merge($lines, $this->findLines($find, $content)); } sort($lines); - $this->_addError($file, self::CODE_PHP_DOC_VAR_NULL, count($matches[0]), $lines); + $this->addError($file, self::CODE_PHP_DOC_VAR_NULL, count($matches[0]), $lines); } return $this; @@ -317,13 +317,15 @@ protected function _validateExistPhpDocVarNull($content, $file) * @param string $file * @return $this */ - protected function _validateSingleAsterisk($content, $file) + protected function validateSingleAsterisk($content, $file) { + //@startSkipCommitHooks $target = '/* @var '; + //@finishSkipCommitHooks str_replace($target, '|||', $content, $count); if ($count) { - $lines = $this->_findLines($target, $content); - $this->_addError($file, self::CODE_PHP_DOC_SINGLE_ASTERISK, $count, $lines); + $lines = $this->findLines($target, $content); + $this->addError($file, self::CODE_PHP_DOC_SINGLE_ASTERISK, $count, $lines); } return $this; @@ -337,7 +339,7 @@ protected function _validateSingleAsterisk($content, $file) * @param bool $once * @return array|int */ - protected function _findLines($find, $content, $once = false) + protected function findLines($find, $content, $once = false) { return LineFinder::findLines($find, $content, $once); } diff --git a/LibHooks/lib/PreCommit/Validator/RedundantCode.php b/LibHooks/lib/PreCommit/Validator/RedundantCode.php index 1b4a1ba..c83c106 100644 --- a/LibHooks/lib/PreCommit/Validator/RedundantCode.php +++ b/LibHooks/lib/PreCommit/Validator/RedundantCode.php @@ -76,19 +76,19 @@ public function validate($content, $file) //find console.log() if ($this->canCheckType($ext, self::JS_CONSOLE) && false !== strpos($str, 'console.log(')) { - $this->_addError($file, self::JS_CONSOLE, $currentString, $line); + $this->addError($file, self::JS_CONSOLE, $currentString, $line); } //find is_null() function if ($this->canCheckType($ext, self::CODE_IS_NULL) && false !== strpos($str, 'is_null(')) { - $this->_addError($file, self::CODE_IS_NULL, $currentString, $line); + $this->addError($file, self::CODE_IS_NULL, $currentString, $line); } //find qqq() if ($this->canCheckType($ext, self::DEBUG_QQQ) && false !== strpos($str, 'qqq')) { - $this->_addError($file, self::DEBUG_QQQ, $currentString, $line); + $this->addError($file, self::DEBUG_QQQ, $currentString, $line); } //find var_dump() if ($this->canCheckType($ext, self::DEBUG_VAR_DUMP) && false !== strpos($str, 'var_dump(')) { - $this->_addError($file, self::DEBUG_VAR_DUMP, $currentString, $line); + $this->addError($file, self::DEBUG_VAR_DUMP, $currentString, $line); } } diff --git a/LibHooks/lib/PreCommit/Validator/TrailingSpace.php b/LibHooks/lib/PreCommit/Validator/TrailingSpace.php index 0e51a1d..212f73b 100644 --- a/LibHooks/lib/PreCommit/Validator/TrailingSpace.php +++ b/LibHooks/lib/PreCommit/Validator/TrailingSpace.php @@ -54,7 +54,7 @@ protected function validateRedundantTrailingSpaces($content, $file) { $matches = array(); if (preg_match_all("~.*?[ \t]+\r?\n~", $content, $matches)) { - $this->_addError( + $this->addError( $file, self::CODE_PHP_REDUNDANT_TRAILING_SPACES, count($matches[0]) @@ -76,7 +76,7 @@ protected function validateTrailingLine($content, $file) $lines = explode("\n", $content); $lastLine = array_pop($lines); if ($lastLine != '') { - $this->_addError($file, self::CODE_PHP_NO_END_TRAILING_LINE); + $this->addError($file, self::CODE_PHP_NO_END_TRAILING_LINE); } return $this; diff --git a/LibHooks/lib/PreCommit/Validator/UnresolvedConflict.php b/LibHooks/lib/PreCommit/Validator/UnresolvedConflict.php index 236e098..229a295 100644 --- a/LibHooks/lib/PreCommit/Validator/UnresolvedConflict.php +++ b/LibHooks/lib/PreCommit/Validator/UnresolvedConflict.php @@ -50,7 +50,7 @@ protected function validateGitConflict($content, $file) { //checking for windows line breaks if (strpos($content, '<<<<<<<'.' HEAD') || strpos($content, "\n>>>>>>> ")) { - $this->_addError( + $this->addError( $file, self::MERGE_CONFLICT ); diff --git a/LibHooks/lib/PreCommit/Validator/XmlParser.php b/LibHooks/lib/PreCommit/Validator/XmlParser.php index 31555dc..d8a2b21 100644 --- a/LibHooks/lib/PreCommit/Validator/XmlParser.php +++ b/LibHooks/lib/PreCommit/Validator/XmlParser.php @@ -49,14 +49,14 @@ public function validate($content, $file) if ($error->level < 3) { return true; } - $this->_addError( + $this->addError( $file, self::CODE_XML_ERROR, str_replace("\n", '', $error->message), $error->line ); } catch (\Exception $e) { - $this->_addError( + $this->addError( $file, self::CODE_XML_ERROR, str_replace("\n", '', $e->getMessage())