Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
class ArraySniff implements Sniff
{


/**
* The limit that the length of a line should not exceed.
*
Expand All @@ -51,8 +50,7 @@ public function register()
T_ARRAY,
T_OPEN_SHORT_ARRAY,
];

}//end register()
}


/**
Expand Down Expand Up @@ -304,8 +302,5 @@ public function process(File $phpcsFile, $stackPtr)

$lineStart = $newLineStart;
}//end while

}//end process()


}//end class
}
}
10 changes: 3 additions & 7 deletions coder_sniffer/Drupal/Sniffs/Attributes/ValidHookNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ValidHookNameSniff implements Sniff
public function register()
{
return [T_ATTRIBUTE];

}//end register()
}


/**
Expand Down Expand Up @@ -75,8 +74,5 @@ public function process(File $phpcsFile, $stackPtr)
}
}
}//end if

}//end process()


}//end class
}
}
17 changes: 6 additions & 11 deletions coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public function register()
T_TRAIT,
T_ENUM,
];

}//end register()
}


/**
Expand Down Expand Up @@ -106,7 +105,7 @@ public function process(File $phpcsFile, $stackPtr)
$openingBrace = $tokens[$stackPtr]['scope_opener'];
if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($tokens[($openingBrace - 1)]['content'] === "\t") {
} elseif ($tokens[($openingBrace - 1)]['content'] === "\t") {
$length = '\t';
} else {
$length = strlen($tokens[($openingBrace - 1)]['content']);
Expand All @@ -129,8 +128,7 @@ public function process(File $phpcsFile, $stackPtr)
$this->processOpen($phpcsFile, $stackPtr);

$this->processClose($phpcsFile, $stackPtr);

}//end process()
}


/**
Expand Down Expand Up @@ -171,7 +169,7 @@ public function processClose(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->replaceToken($closeBrace, $phpcsFile->eolChar.$phpcsFile->eolChar.$tokens[$closeBrace]['content']);
$phpcsFile->fixer->replaceToken($closeBrace, $phpcsFile->eolChar . $phpcsFile->eolChar . $tokens[$closeBrace]['content']);

$phpcsFile->fixer->endChangeset();
}
Expand All @@ -188,8 +186,5 @@ public function processClose(File $phpcsFile, $stackPtr)
$data = [$tokens[$stackPtr]['content']];
$phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data);
}

}//end processClose()


}//end class
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function register()
T_NAME_FULLY_QUALIFIED,
T_NAME_QUALIFIED,
];

}//end register()
}


/**
Expand Down Expand Up @@ -201,8 +200,5 @@ public function process(File $phpcsFile, $stackPtr)

$phpcsFile->fixer->endChangeset();
}//end if

}//end process()


}//end class
}
}
10 changes: 3 additions & 7 deletions coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class PropertyDeclarationSniff implements Sniff
public function register()
{
return [T_VAR];

}//end register()
}


/**
Expand All @@ -55,8 +54,5 @@ public function process(File $phpcsFile, $stackPtr)
if ($fix === true) {
$phpcsFile->fixer->replaceToken($stackPtr, 'public');
}

}//end process()


}//end class
}
}
20 changes: 8 additions & 12 deletions coder_sniffer/Drupal/Sniffs/Classes/UseGlobalClassSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class UseGlobalClassSniff implements Sniff
public function register()
{
return [T_USE];

}//end register()
}


/**
Expand Down Expand Up @@ -74,7 +73,7 @@ public function process(File $phpcsFile, $stackPtr)

$lineStart = $stackPtr;
// Iterate through a potential multiline use statement.
while (false !== $lineEnd = $phpcsFile->findNext([T_SEMICOLON, T_COMMA], ($lineStart + 1), ($stmtEnd + 1))) {
while (($lineEnd = $phpcsFile->findNext([T_SEMICOLON, T_COMMA], ($lineStart + 1), ($stmtEnd + 1))) !== false) {
// Skip function imports.
if ($phpcsFile->findNext(T_STRING, $lineStart, $lineEnd, false, 'function') !== false) {
$lineStart = $lineEnd;
Expand Down Expand Up @@ -108,11 +107,11 @@ public function process(File $phpcsFile, $stackPtr)
// If there are lines before this one,
// then leave the ending delimiter in place.
$end = ($lineEnd - 1);
} else if ($tokens[$lineEnd]['code'] === T_COMMA) {
} elseif ($tokens[$lineEnd]['code'] === T_COMMA) {
// If there are lines after, but not before,
// then leave the use keyword.
$start = $class;
} else if ($tokens[$next]['code'] === T_USE) {
} elseif ($tokens[$next]['code'] === T_USE) {
// If the whole statement is removed, and there is one after it,
// then also remove the linebreaks.
$end = ($next - 1);
Expand All @@ -125,17 +124,14 @@ public function process(File $phpcsFile, $stackPtr)
// Find all usages of the class, and add a leading backslash.
// Only start looking after the end of the use statement block.
$i = $bodyStart;
while (false !== $i = $phpcsFile->findNext(T_STRING, ($i + 1), null, false, $aliasName)) {
$phpcsFile->fixer->replaceToken($i, '\\'.$className);
while (($i = $phpcsFile->findNext(T_STRING, ($i + 1), null, false, $aliasName)) !== false) {
$phpcsFile->fixer->replaceToken($i, '\\' . $className);
}

$phpcsFile->fixer->endChangeset();
}//end if

$lineStart = $lineEnd;
}//end while

}//end process()


}//end class
}
}
14 changes: 5 additions & 9 deletions coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public function register()
T_TRAIT,
T_ENUM,
];

}//end register()
}


/**
Expand Down Expand Up @@ -118,11 +117,11 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->beginChangeset();
$comment = '';
for ($i = $commentEnd; $tokens[$i]['code'] === T_COMMENT; $i--) {
$comment = ' *'.ltrim($tokens[$i]['content'], '/* ').$comment;
$comment = ' *' . ltrim($tokens[$i]['content'], '/* ') . $comment;
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->replaceToken($commentEnd, "/**\n".rtrim($comment, "*/\n")."\n */");
$phpcsFile->fixer->replaceToken($commentEnd, "/**\n" . rtrim($comment, "*/\n") . "\n */");
$phpcsFile->fixer->endChangeset();
}

Expand Down Expand Up @@ -167,8 +166,5 @@ public function process(File $phpcsFile, $stackPtr)
}
}
}

}//end process()


}//end class
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class DataTypeNamespaceSniff implements Sniff
public function register()
{
return [T_USE];

}//end register()
}


/**
Expand Down Expand Up @@ -93,15 +92,12 @@ public function process(File $phpcsFile, $stackPtr)
$data = [$tokens[$tag]['content']];
$fix = $phpcsFile->addFixableError($error, ($tag + 2), 'DataTypeNamespace', $data);
if ($fix === true) {
$replacement = '\\'.$fullNamespace.substr($tokens[($tag + 2)]['content'], strlen($className));
$replacement = '\\' . $fullNamespace . substr($tokens[($tag + 2)]['content'], strlen($className));
$phpcsFile->fixer->replaceToken(($tag + 2), $replacement);
}
}

$tag = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($tag + 1));
}//end while

}//end process()


}//end class
}
}
34 changes: 15 additions & 19 deletions coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public function register()
}

return [T_DOC_COMMENT_TAG];

}//end register()
}


/**
Expand Down Expand Up @@ -96,7 +95,7 @@ public function process(File $phpcsFile, $stackPtr)

// The standard format for the deprecation text is:
// @deprecated in %in-version% and is removed from %removal-version%. %extra-info%.
$standardFormat = "@deprecated in %%deprecation-version%% and is removed from %%removal-version%%. %%extra-info%%.";
$standardFormat = '@deprecated in %%deprecation-version%% and is removed from %%removal-version%%. %%extra-info%%.';

// Use (?U) 'ungreedy' before the removal-version so that only the text
// up to the first dot+space is matched, as there may be more than one
Expand All @@ -110,7 +109,7 @@ public function process(File $phpcsFile, $stackPtr)
// The full text does not match the standard. Try to find fixes by
// testing with a relaxed set of criteria, based on common
// formatting variations. This is designed for Core fixes only.
$error = "The text '@deprecated %s' does not match the standard format: ".$standardFormat;
$error = "The text '@deprecated %s' does not match the standard format: " . $standardFormat;
// All of the standard text should be on the first comment line, so
// try to match with common formatting errors to allow an automatic
// fix. If not possible then report a normal error.
Expand All @@ -131,9 +130,9 @@ public function process(File $phpcsFile, $stackPtr)
// It is a Drupal core deprecation and is fixable.
if (empty($matchesFix[1]) === false && $this->debug === true) {
// For info, to check it is acceptable to remove the text in [1].
echo('DEBUG: File: '.$phpcsFile->path.', line '.$tokens[($stackPtr)]['line'].PHP_EOL);
echo('DEBUG: "@deprecated '.$text1.'"'.PHP_EOL);
echo('DEBUG: Fix will remove: "'.$matchesFix[1].'"'.PHP_EOL);
echo('DEBUG: File: ' . $phpcsFile->path . ', line ' . $tokens[($stackPtr)]['line'] . PHP_EOL);
echo('DEBUG: "@deprecated ' . $text1 . '"' . PHP_EOL);
echo('DEBUG: Fix will remove: "' . $matchesFix[1] . '"' . PHP_EOL);
}

$ver1 = str_Replace(['-dev', 'x'], ['', '0'], trim($matchesFix[5], '.'));
Expand All @@ -147,14 +146,14 @@ public function process(File $phpcsFile, $stackPtr)
$ver2 .= '.0';
}

$correctedText = trim('in drupal:'.$ver1.' and is removed from drupal:'.$ver2.'. '.trim($matchesFix[14]));
$correctedText = trim('in drupal:' . $ver1 . ' and is removed from drupal:' . $ver2 . '. ' . trim($matchesFix[14]));
// If $correctedText is longer than 65 this will make the whole line
// exceed 80 so give a warning if running with debug.
if (strlen($correctedText) > 65 && $this->debug === true) {
echo('WARNING: File '.$phpcsFile->path.', line '.$tokens[($stackPtr)]['line'].PHP_EOL);
echo('WARNING: Original = * @deprecated '.$text1.PHP_EOL);
echo('WARNING: Corrected = * @deprecated '.$correctedText.PHP_EOL);
echo('WARNING: New line length '.(strlen($correctedText) + 15).' exceeds standard 80 character limit'.PHP_EOL);
echo('WARNING: File ' . $phpcsFile->path . ', line ' . $tokens[($stackPtr)]['line'] . PHP_EOL);
echo('WARNING: Original = * @deprecated ' . $text1 . PHP_EOL);
echo('WARNING: Corrected = * @deprecated ' . $correctedText . PHP_EOL);
echo('WARNING: New line length ' . (strlen($correctedText) + 15) . ' exceeds standard 80 character limit' . PHP_EOL);
}

$fix = $phpcsFile->addFixableError($error, $key, 'IncorrectTextLayout', [$fullText]);
Expand Down Expand Up @@ -184,7 +183,7 @@ public function process(File $phpcsFile, $stackPtr)
// except for missing extra info. This is a common fault so provide
// a separate check and message for this.
if ($matches[3] === '') {
$error = 'The @deprecated tag must have %extra-info%. The standard format is: '.str_replace('%%', '%', $standardFormat);
$error = 'The @deprecated tag must have %extra-info%. The standard format is: ' . str_replace('%%', '%', $standardFormat);
$phpcsFile->addError($error, $stackPtr, 'MissingExtraInfo', []);
}
}//end if
Expand Down Expand Up @@ -220,12 +219,9 @@ public function process(File $phpcsFile, $stackPtr)
$content = substr($crLink, 0, -(strlen($matches[4])));
$phpcsFile->fixer->replaceToken($string, $content);
}//end if
} else if (empty($matches) === true) {
} elseif (empty($matches) === true) {
$error = "The @see url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n";
$phpcsFile->addWarning($error, $seeTag, 'DeprecatedWrongSeeUrlFormat', [$crLink]);
}

}//end process()


}//end class
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class DocCommentAlignmentSniff implements Sniff
public function register()
{
return [T_DOC_COMMENT_OPEN_TAG];

}//end register()
}


/**
Expand Down Expand Up @@ -127,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr)
if ($fix === true) {
$phpcsFile->fixer->addContent($i, ' ');
}
} else if ($tokens[($i + 2)]['code'] === T_DOC_COMMENT_TAG
} elseif ($tokens[($i + 2)]['code'] === T_DOC_COMMENT_TAG
&& $tokens[($i + 1)]['content'] !== ' '
// Special @code/@endcode/@see tags can have more than 1 space.
&& in_array(
Expand All @@ -149,8 +148,5 @@ public function process(File $phpcsFile, $stackPtr)
}
}//end if
}//end for

}//end process()


}//end class
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class DocCommentLongArraySyntaxSniff implements Sniff
public function register()
{
return [T_DOC_COMMENT_OPEN_TAG];

}//end register()
}


/**
Expand Down Expand Up @@ -70,8 +69,5 @@ public function process(File $phpcsFile, $stackPtr)
}
}
} while ($codeStart !== false);

}//end process()


}//end class
}
}
Loading