diff --git a/.gitignore b/.gitignore index 62097d8..decb93a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ # Tests .phpunit.result.cache + +# Code coverage report +html-coverage diff --git a/composer.json b/composer.json index 46a9432..a2e4d1c 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "scripts": { "parallel-lint": "parallel-lint . --exclude vendor", "phpcs": "phpcs -p -s", - "phpunit": "phpunit", + "phpunit": "php -d extension=pcov.so -d pcov.enabled=1 -d pcov.directory=. vendor/bin/phpunit", "lint": [ "@parallel-lint", "@phpcs" diff --git a/phpunit.xml b/phpunit.xml index 4f789e3..adc104b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,4 +17,14 @@ ./src/Tests + + + ./src/Sniffs + + + + + + + diff --git a/src/Sniffs/Attributes/AttributeAlignmentSniff.php b/src/Sniffs/Attributes/AttributeAlignmentSniff.php index c1ad871..436a2b8 100644 --- a/src/Sniffs/Attributes/AttributeAlignmentSniff.php +++ b/src/Sniffs/Attributes/AttributeAlignmentSniff.php @@ -92,12 +92,10 @@ public function process( File $phpcsFile, $stackPtr ) { ); } - // Clear all of the other whitespace tokens before the attribute; this - // works for both cases because if the attribute was the start of the - // line then $iii will start at $stackPtr and the loop never runs - for ( $iii = $targetLineStart; $iii < $stackPtr - 1; $iii++ ) { - $phpcsFile->fixer->replaceToken( $iii, '' ); - } + // Apparently we don't need to worry about the other whitespace tokens + // that came before the stack pointer, I could not figure out a way to + // trigger needing to remove them, so the code for that was removed + // since it was untested and potentially unneeded. $phpcsFile->fixer->endChangeset(); } @@ -117,7 +115,11 @@ private function getLineStart( File $phpcsFile, int $stackPtr ): int|false { true ); if ( $prevNonWhitespace === false ) { + // There were no tokens before this in the file, should be + // impossible + // @codeCoverageIgnoreStart return false; + // @codeCoverageIgnoreEnd } $tokens = $phpcsFile->getTokens(); $stackPtrLine = $tokens[$stackPtr]['line']; diff --git a/src/Tests/data/AttributeAlignment/wrong.php b/src/Tests/data/AttributeAlignment/wrong.php index 5e9d2dd..ded6643 100644 --- a/src/Tests/data/AttributeAlignment/wrong.php +++ b/src/Tests/data/AttributeAlignment/wrong.php @@ -1,7 +1,7 @@