Skip to content

Commit

Permalink
Refactored #39: Apply Symphony2 coding standards
Browse files Browse the repository at this point in the history
 - Applied standards.
  • Loading branch information
andkirby committed Dec 2, 2015
1 parent ee35820 commit 795a029
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
28 changes: 14 additions & 14 deletions LibHooks/lib/PreCommit/Validator/CodingStandardPhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class CodingStandardPhtml extends AbstractValidator
*/
public function validate($content, $file)
{
$this->_validateGaps($content, $file);
$this->_validateCodeStyleByLines($content, $file);
$this->validateGaps($content, $file);
$this->validateCodeStyleByLines($content, $file);

return !$this->errorCollector->hasErrors();
}
Expand All @@ -59,7 +59,7 @@ public function validate($content, $file)
* @param string $file
* @return $this
*/
protected function _validateGaps($content, $file)
protected function validateGaps($content, $file)
{
$content = preg_replace('/\r/', '', $content);

Expand All @@ -78,20 +78,20 @@ protected function _validateGaps($content, $file)
* @param string $file
* @return $this
*/
protected function _validateCodeStyleByLines($content, $file)
protected function validateCodeStyleByLines($content, $file)
{
$content = $this->_filterContent($content);
$content = $this->filterContent($content);
$originalArr = preg_split('/\x0A\x0D|\x0D\x0A|\x0A|\x0D/', $content);
foreach ($originalArr as $line => $str) {
$str = trim($str);
if (!$str) {
//skip empty line
continue;
}
$this->_validateStringAlternativeSyntaxUsage($file, $str, $line);
$this->_validateStringNoUnderscoreInVariableName($file, $str, $line);
$this->_validateStringNoProtectedMethodUsage($file, $str, $line);
$this->_validateStringNoClassesUsage($file, $str, $line);
$this->validateStringAlternativeSyntaxUsage($file, $str, $line);
$this->validateStringNoUnderscoreInVariableName($file, $str, $line);
$this->validateStringNoProtectedMethodUsage($file, $str, $line);
$this->validateStringNoClassesUsage($file, $str, $line);
}

return $this;
Expand All @@ -105,7 +105,7 @@ protected function _validateCodeStyleByLines($content, $file)
* @param string $content
* @return string
*/
protected function _filterContent($content)
protected function filterContent($content)
{
return preg_replace('/<script(\n|\r|.)*?<\/script>/', '', $content);
}
Expand All @@ -118,7 +118,7 @@ protected function _filterContent($content)
* @param int $line
* @return $this
*/
protected function _validateStringAlternativeSyntaxUsage($file, $str, $line)
protected function validateStringAlternativeSyntaxUsage($file, $str, $line)
{
$operators = 'elseif|else if|if|switch|foreach|for|while';
if (preg_match('/[^A-z0-9]+(?:'.$operators.')[^A-z]?\(.*?\).*/i', $str, $b)
Expand All @@ -139,7 +139,7 @@ protected function _validateStringAlternativeSyntaxUsage($file, $str, $line)
* @param int $line
* @return $this
*/
protected function _validateStringNoUnderscoreInVariableName($file, $str, $line)
protected function validateStringNoUnderscoreInVariableName($file, $str, $line)
{
if (false !== strpos($str, '$')
&& preg_match_all('/\$\w*_\w*/', $str, $matches)
Expand All @@ -165,7 +165,7 @@ protected function _validateStringNoUnderscoreInVariableName($file, $str, $line)
* @param int $line
* @return $this
*/
protected function _validateStringNoProtectedMethodUsage($file, $str, $line)
protected function validateStringNoProtectedMethodUsage($file, $str, $line)
{
if (preg_match('/\$this-\>_[^_]/', $str)) {
$this->_addError($file, self::CODE_PHTML_PROTECTED_METHOD, $str, $line);
Expand All @@ -182,7 +182,7 @@ protected function _validateStringNoProtectedMethodUsage($file, $str, $line)
* @param int $line
* @return $this
*/
protected function _validateStringNoClassesUsage($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);
Expand Down
12 changes: 6 additions & 6 deletions LibHooks/lib/PreCommit/Validator/FileStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class FileStyle extends AbstractValidator
*/
public function validate($content, $file)
{
$this->_validateTabIndents($content, $file);
$this->_validateLineBreaks($content, $file);
$this->_validateBom($content, $file);
$this->validateTabIndents($content, $file);
$this->validateLineBreaks($content, $file);
$this->validateBom($content, $file);

return !$this->errorCollector->hasErrors();
}
Expand All @@ -56,7 +56,7 @@ public function validate($content, $file)
* @param string $file
* @return $this
*/
protected function _validateTabIndents($content, $file)
protected function validateTabIndents($content, $file)
{
if (preg_match('~^[^\t]*?\t~s', $content, $matches)) {
//$line = count(explode("\n", $matches[0]));
Expand All @@ -77,7 +77,7 @@ protected function _validateTabIndents($content, $file)
* @param string $file
* @return $this
*/
protected function _validateLineBreaks($content, $file)
protected function validateLineBreaks($content, $file)
{
//checking for windows line breaks
if (preg_match_all('~(\r\n)~s', $content, $lnMatches)) {
Expand All @@ -98,7 +98,7 @@ protected function _validateLineBreaks($content, $file)
* @param string $file
* @return $this
*/
protected function _validateBom($content, $file)
protected function validateBom($content, $file)
{
if (substr($content, 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf)) {
$this->_addError($file, self::CODE_FILE_BOM);
Expand Down
2 changes: 1 addition & 1 deletion LibHooks/lib/PreCommit/Validator/IssueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function validate($message, $file)
*
* @return Config
*/
protected function _getConfig()
protected function getConfig()
{
return Config::getInstance();
}
Expand Down
17 changes: 8 additions & 9 deletions LibHooks/lib/PreCommit/Validator/ParentThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class ParentThis extends AbstractValidator
*/
public function validate($content, $file)
{
$parentClass = $this->_getExtendClass($content);
$parentClass = $this->getExtendClass($content);
if (!$parentClass) {
return false;
}
$this->_validateParentClassInReturn($parentClass, $content, $file);
$this->validateParentClassInReturn($parentClass, $content, $file);

$parentClassAlias = $this->_getClassAlias($parentClass, $content);
$parentClassAlias = $this->getClassAlias($parentClass, $content);
if ($parentClassAlias) {
$this->_validateParentClassInReturn($parentClassAlias, $content, $file);
$this->validateParentClassInReturn($parentClassAlias, $content, $file);
}

return !$this->errorCollector->hasErrors();
Expand All @@ -54,7 +54,7 @@ public function validate($content, $file)
* @param string $content
* @return string|null
*/
protected function _getExtendClass($content)
protected function getExtendClass($content)
{
$matches = array();
preg_match('/ extends[ ]+([A-z0-9_\x92]+)/', $content, $matches);
Expand All @@ -70,7 +70,7 @@ protected function _getExtendClass($content)
* @param string $file
* @return $this
*/
protected function _validateParentClassInReturn($parentClass, $content, $file)
protected function validateParentClassInReturn($parentClass, $content, $file)
{
$regularClass = ltrim($parentClass, '\\'); //remove left "\"
$regularClass = str_replace('\\', '\x5C', $regularClass); //set codes instead "\"
Expand All @@ -88,7 +88,7 @@ protected function _validateParentClassInReturn($parentClass, $content, $file)
* @param string $content
* @return null|string
*/
protected function _getClassAlias($class, $content)
protected function getClassAlias($class, $content)
{
$matches = array();
if (strpos($class, '\\')) {
Expand All @@ -97,8 +97,7 @@ protected function _getClassAlias($class, $content)
return null;
}
$parentPath = substr($class, 0, strpos($class, "\x5C"));
if (
preg_match('~use ([A-z0-9\x5C_]+)\x5C'.$parentPath.';~', $content, $matches)
if (preg_match('~use ([A-z0-9\x5C_]+)\x5C'.$parentPath.';~', $content, $matches)
|| preg_match('~use ([A-z0-9\x5C_]+) as '.$parentPath.';~', $content, $matches)
) {
return $matches[1].substr($class, strpos($class, "\x5C"));
Expand Down
8 changes: 4 additions & 4 deletions LibHooks/lib/PreCommit/Validator/TrailingSpace.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class TrailingSpace extends AbstractValidator
*/
public function validate($content, $file)
{
$this->_validateRedundantTrailingSpaces($content, $file);
$this->_validateTrailingLine($content, $file);
$this->validateRedundantTrailingSpaces($content, $file);
$this->validateTrailingLine($content, $file);

return !$this->errorCollector->hasErrors();
}
Expand All @@ -50,7 +50,7 @@ public function validate($content, $file)
* @param string $file
* @return $this
*/
protected function _validateRedundantTrailingSpaces($content, $file)
protected function validateRedundantTrailingSpaces($content, $file)
{
$matches = array();
if (preg_match_all("~.*?[ \t]+\r?\n~", $content, $matches)) {
Expand All @@ -71,7 +71,7 @@ protected function _validateRedundantTrailingSpaces($content, $file)
* @param string $file
* @return $this
*/
protected function _validateTrailingLine($content, $file)
protected function validateTrailingLine($content, $file)
{
$lines = explode("\n", $content);
$lastLine = array_pop($lines);
Expand Down

0 comments on commit 795a029

Please sign in to comment.