Skip to content

Commit

Permalink
Merge pull request #179 from PHPCSStandards/feature/various-minor-fixes
Browse files Browse the repository at this point in the history
CS/QA: various minor fixes
  • Loading branch information
jrfnl authored Dec 7, 2022
2 parents 0d4836b + b5113ce commit d8e72f1
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 56 deletions.
1 change: 1 addition & 0 deletions NormalizedArrays/Sniffs/Arrays/CommaAfterLastSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->fixer->beginChangeset();

for ($i = $start; $i <= $end; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}
Expand Down
13 changes: 7 additions & 6 deletions Universal/Sniffs/Classes/DisallowAnonClassParenthesesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ final class DisallowAnonClassParenthesesSniff implements Sniff
*/
public function register()
{
return [
\T_ANON_CLASS,
];
return [\T_ANON_CLASS];
}

/**
Expand Down Expand Up @@ -80,8 +78,9 @@ public function process(File $phpcsFile, $stackPtr)
// @codeCoverageIgnoreEnd
}

$closer = $tokens[$nextNonEmpty]['parenthesis_closer'];
$hasParams = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), $closer, true);
$opener = $nextNonEmpty;
$closer = $tokens[$opener]['parenthesis_closer'];
$hasParams = $phpcsFile->findNext(Tokens::$emptyTokens, ($opener + 1), $closer, true);
if ($hasParams !== false) {
// There is something between the parentheses. Ignore.
$phpcsFile->recordMetric($stackPtr, self::METRIC_NAME, 'yes, with parameter(s)');
Expand All @@ -98,13 +97,15 @@ public function process(File $phpcsFile, $stackPtr)

if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
for ($i = $nextNonEmpty; $i <= $closer; $i++) {

for ($i = $opener; $i <= $closer; $i++) {
if (isset(Tokens::$commentTokens[$tokens[$i]['code']]) === true) {
continue;
}

$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->endChangeset();
}
}
Expand Down
4 changes: 1 addition & 3 deletions Universal/Sniffs/Classes/DisallowFinalClassSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ final class DisallowFinalClassSniff implements Sniff
*/
public function register()
{
return [
\T_CLASS,
];
return [\T_CLASS];
}

/**
Expand Down
16 changes: 8 additions & 8 deletions Universal/Sniffs/Classes/ModifierKeywordOrderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
/**
* Standardize the modifier keyword order for class declarations.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*/
final class ModifierKeywordOrderSniff implements Sniff
{

/**
* Name of the metric.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -35,7 +35,7 @@ final class ModifierKeywordOrderSniff implements Sniff
/**
* Order preference: abstract/final readonly.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -44,7 +44,7 @@ final class ModifierKeywordOrderSniff implements Sniff
/**
* Order preference: readonly abstract/final.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -59,7 +59,7 @@ final class ModifierKeywordOrderSniff implements Sniff
*
* Defaults to "extendability readonly".
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -68,7 +68,7 @@ final class ModifierKeywordOrderSniff implements Sniff
/**
* Returns an array of tokens this test wants to listen for.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @return array
*/
Expand All @@ -80,7 +80,7 @@ public function register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
Expand Down Expand Up @@ -178,7 +178,7 @@ public function process(File $phpcsFile, $stackPtr)
/**
* Throw the error and potentially fix it.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $firstKeyword The position of the first keyword found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ final class RequireAnonClassParenthesesSniff implements Sniff
*/
public function register()
{
return [
\T_ANON_CLASS,
];
return [\T_ANON_CLASS];
}

/**
Expand Down
4 changes: 1 addition & 3 deletions Universal/Sniffs/Classes/RequireFinalClassSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ final class RequireFinalClassSniff implements Sniff
*/
public function register()
{
return [
\T_CLASS,
];
return [\T_CLASS];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ final class LowercaseClassResolutionKeywordSniff implements Sniff
*/
public function register()
{
return [
\T_STRING,
];
return [\T_STRING];
}

/**
Expand Down
18 changes: 9 additions & 9 deletions Universal/Sniffs/Constants/ModifierKeywordOrderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
/**
* Standardize the modifier keyword order for OO constant declarations.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*/
final class ModifierKeywordOrderSniff implements Sniff
{

/**
* Name of the metric.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -35,7 +35,7 @@ final class ModifierKeywordOrderSniff implements Sniff
/**
* Order preference: final visibility.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -44,7 +44,7 @@ final class ModifierKeywordOrderSniff implements Sniff
/**
* Order preference: visibility final.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -59,7 +59,7 @@ final class ModifierKeywordOrderSniff implements Sniff
*
* Defaults to "final visibility".
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var string
*/
Expand All @@ -68,7 +68,7 @@ final class ModifierKeywordOrderSniff implements Sniff
/**
* Tokens which can be constant modifier keywords.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @var array
*/
Expand All @@ -79,7 +79,7 @@ final class ModifierKeywordOrderSniff implements Sniff
/**
* Returns an array of tokens this test wants to listen for.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @return array
*/
Expand All @@ -94,7 +94,7 @@ public function register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
Expand Down Expand Up @@ -175,7 +175,7 @@ public function process(File $phpcsFile, $stackPtr)
/**
* Throw the error and potentially fix it.
*
* @since 1.0.0-alpha4
* @since 1.0.0
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $firstKeyword The position of the first keyword found.
Expand Down
6 changes: 2 additions & 4 deletions Universal/Sniffs/ControlStructures/DisallowLonelyIfSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ final class DisallowLonelyIfSniff implements Sniff
*/
public function register()
{
return [
\T_ELSE,
];
return [\T_ELSE];
}

/**
Expand Down Expand Up @@ -274,7 +272,7 @@ public function process(File $phpcsFile, $stackPtr)
}

// Remove the inner scope closer.
$phpcsFile->fixer->replaceToken($innerScopeCloser, '');
$phpcsFile->fixer->replaceToken($innerScopeCloser, '');
$i = ($innerScopeCloser - 1);

// Handle alternative syntax for the closer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function process(File $phpcsFile, $stackPtr)
*/
$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['code'] !== \T_CLOSE_CURLY_BRACKET) {
// Parse error. Not our concern.
// Parse error or mixing braced and non-braced. Not our concern.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function process(File $phpcsFile, $stackPtr)
if ($name !== '') {
// Named namespace.
$phpcsFile->recordMetric($stackPtr, self::METRIC_NAME, 'yes');

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function register()
$this->allowedTokens += Collections::namespacedNameTokens();

/*
* Remove potential nullsafe object operator. In/decrement not allowed in write context,
* Remove nullsafe object operator. In/decrement not allowed in write context,
* so ignore.
*/
unset($this->allowedTokens[\T_NULLSAFE_OBJECT_OPERATOR]);
Expand Down Expand Up @@ -184,15 +184,13 @@ public function process(File $phpcsFile, $stackPtr)

$fix = $phpcsFile->addFixableError($error, $stackPtr, $errorCode, $data);

if ($fix === false) {
return $end;
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken($stackPtr, '');
$phpcsFile->fixer->addContentBefore($start, $tokens[$stackPtr]['content']);
$phpcsFile->fixer->endChangeset();
}

$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken($stackPtr, '');
$phpcsFile->fixer->addContentBefore($start, $tokens[$stackPtr]['content']);
$phpcsFile->fixer->endChangeset();

return $end;
}
}
4 changes: 1 addition & 3 deletions Universal/Sniffs/PHP/OneStatementInShortEchoTagSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ final class OneStatementInShortEchoTagSniff implements Sniff
*/
public function register()
{
return [
\T_OPEN_TAG_WITH_ECHO,
];
return [\T_OPEN_TAG_WITH_ECHO];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Universal/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* - Precision alignment *within* text strings (multi-line text strings, heredocs, nowdocs)
* will NOT be flagged by this sniff.
* - The fixer works based on "best guess" and may not always result in the desired indentation.
* - This fixer will use tabs or spaces based on whether tabs where present in the original indent.
* - This fixer will use tabs or spaces based on whether tabs were present in the original indent.
* Use the PHPCS native `Generic.WhiteSpace.DisallowTabIndent` or the
* `Generic.WhiteSpace.DisallowSpaceIndent` sniff to clean up the results if so desired.
*
Expand Down Expand Up @@ -304,7 +304,7 @@ public function process(File $phpcsFile, $stackPtr)
case \T_END_NOWDOC:
/*
* PHPCS does not execute tab replacement in heredoc/nowdoc closer
* tokens (last checked: PHPCS 3.7.1), so handle this ourselves.
* tokens prior to PHPCS 3.7.2, so handle this ourselves.
*/
$content = $tokens[$i]['content'];
if (\strpos($tokens[$i]['content'], "\t") !== false) {
Expand Down
1 change: 0 additions & 1 deletion Universal/Tests/Arrays/DuplicateArrayKeyUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace PHPCSExtra\Universal\Tests\Arrays;

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
use PHPCSUtils\BackCompat\Helper;

/**
* Unit test class for the DuplicateArrayKey sniff.
Expand Down
2 changes: 1 addition & 1 deletion Universal/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function shouldSkipTest()
* next to impossible.
* But having to continuously restart builds is getting silly.
*/
return (PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 5);
return (\PHP_MAJOR_VERSION === 5 && \PHP_MINOR_VERSION === 5);
}

/**
Expand Down

0 comments on commit d8e72f1

Please sign in to comment.