Skip to content

Commit

Permalink
Fix static tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmalevanec committed Apr 18, 2019
1 parent bed152b commit 92d0f93
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Sniffs\Annotation;

use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -261,14 +262,13 @@ public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr)
$noAlignmentPositions = [];
$actualPositions = [];
$stackPtr = null;
foreach ($tokens[$commentStartPtr]['comment_tags'] as $position => $tag) {
foreach ($tokens[$commentStartPtr]['comment_tags'] as $tag) {
$content = $tokens[$tag]['content'];
if (preg_match('/^@/', $content) && ($tokens[$tag]['line'] === $tokens[$tag + 2]['line'])) {
$noAlignmentPositions[] = $tokens[$tag + 1]['column'] + 1;
$actualPositions[] = $tokens[$tag + 2]['column'];
$stackPtr = $stackPtr ?? $tag;
}

}

if (!$this->allTagsAligned($actualPositions)
Expand All @@ -281,11 +281,26 @@ public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr)
}
}

private function allTagsAligned(array $actualPositions) {
/**
* Check whether all docblock params are aligned.
*
* @param array $actualPositions
* @return bool
*/
private function allTagsAligned(array $actualPositions)
{
return count(array_unique($actualPositions)) === 1;
}

private function noneTagsAligned(array $actualPositions, array $noAlignmentPositions) {
/**
* Check whether all docblock params are not aligned.
*
* @param array $actualPositions
* @param array $noAlignmentPositions
* @return bool
*/
private function noneTagsAligned(array $actualPositions, array $noAlignmentPositions)
{
return $actualPositions === $noAlignmentPositions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private function getMethodArguments(File $phpcsFile, int $openParenthesisPtr, in
private function getMethodParameters(array $paramDefinitions): array
{
$paramName = [];
for ($i = 0; $i < count($paramDefinitions); $i++) {
$paramCount = count($paramDefinitions);
for ($i = 0; $i < $paramCount; $i++) {
if (isset($paramDefinitions[$i]['paramName'])) {
$paramName[] = $paramDefinitions[$i]['paramName'];
}
Expand Down Expand Up @@ -371,10 +372,11 @@ private function validateDuplicateAnnotationDoesnotExists(
$parametersCount = count($paramPointers);
if ($argumentsCount <= $parametersCount && $argumentsCount > 0) {
$duplicateParameters = [];
for ($i = 0; $i < count($paramDefinitions); $i++) {
$paramCount = count($paramDefinitions);
for ($i = 0; $i < $paramCount; $i++) {
if (isset($paramDefinitions[$i]['paramName'])) {
$parameterContent = $paramDefinitions[$i]['paramName'];
for ($j = $i + 1; $j < count($paramDefinitions); $j++) {
for ($j = $i + 1; $j < $paramCount; $j++) {
if (isset($paramDefinitions[$j]['paramName'])
&& $parameterContent === $paramDefinitions[$j]['paramName']
) {
Expand Down Expand Up @@ -517,7 +519,7 @@ private function validateMethodParameterAnnotations(
$paramPointers
);
$tokens = $phpcsFile->getTokens();
for ($ptr = 0; $ptr < count($methodArguments); $ptr++) {
for ($ptr = 0; $ptr < $argumentCount; $ptr++) {
if (isset($paramPointers[$ptr])) {
$this->validateArgumentNameInParameterAnnotationExists(
$stackPtr,
Expand Down Expand Up @@ -614,7 +616,8 @@ private function validateFormattingConsistency(
$argumentPositions = [];
$commentPositions = [];
$tokens = $phpcsFile->getTokens();
for ($ptr = 0; $ptr < count($methodArguments); $ptr++) {
$argumentCount = count($methodArguments);
for ($ptr = 0; $ptr < $argumentCount; $ptr++) {
if (isset($paramPointers[$ptr])) {
$paramContent = $tokens[$paramPointers[$ptr] + 2]['content'];
$paramDefinition = $paramDefinitions[$ptr];
Expand Down

0 comments on commit 92d0f93

Please sign in to comment.