From 10c0968417b16b693ee018b249319b4471c5271e Mon Sep 17 00:00:00 2001 From: Antonio Mangiacapra <11173091+antonioeatgoat@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:44:22 +0200 Subject: [PATCH] Apply the new rules to the current code There will be a lot of fun. --- Inpsyde/Helpers/Boundaries.php | 18 ++++----- Inpsyde/Helpers/FunctionDocBlock.php | 20 +++++----- Inpsyde/Helpers/FunctionReturnStatement.php | 6 +-- Inpsyde/Helpers/Functions.php | 22 +++++------ Inpsyde/Helpers/Misc.php | 8 ++-- Inpsyde/Helpers/Names.php | 6 +-- Inpsyde/Helpers/Objects.php | 16 ++++---- Inpsyde/Helpers/WpHooks.php | 10 ++--- .../ArgumentTypeDeclarationSniff.php | 4 +- .../DisableMagicSerializeSniff.php | 2 +- .../ForbiddenPublicPropertySniff.php | 6 +-- .../CodeQuality/FunctionBodyStartSniff.php | 22 +++++------ .../CodeQuality/FunctionLengthSniff.php | 24 ++++++------ .../CodeQuality/HookClosureReturnSniff.php | 6 +-- .../Sniffs/CodeQuality/LineLengthSniff.php | 33 +++++++++------- .../Sniffs/CodeQuality/NestingLevelSniff.php | 18 ++++----- .../Sniffs/CodeQuality/NoAccessorsSniff.php | 8 ++-- .../NoRootNamespaceFunctionsSniff.php | 2 +- .../CodeQuality/NoTopLevelDefineSniff.php | 2 +- Inpsyde/Sniffs/CodeQuality/Psr4Sniff.php | 6 +-- .../ReturnTypeDeclarationSniff.php | 14 +++---- .../Sniffs/CodeQuality/StaticClosureSniff.php | 6 +-- .../Sniffs/CodeQuality/VariablesNameSniff.php | 12 +++--- tests/cases/FixturesTest.php | 4 +- tests/src/FixtureContentParser.php | 38 +++++++++---------- 25 files changed, 159 insertions(+), 154 deletions(-) diff --git a/Inpsyde/Helpers/Boundaries.php b/Inpsyde/Helpers/Boundaries.php index 12de08b..73a6bc5 100644 --- a/Inpsyde/Helpers/Boundaries.php +++ b/Inpsyde/Helpers/Boundaries.php @@ -46,7 +46,7 @@ public static function functionBoundaries(File $file, int $position): array $tokens = $file->getTokens(); if ( - !in_array( + ! in_array( $tokens[$position]['code'] ?? null, array_keys(Collections::functionDeclarationTokens()), true @@ -68,7 +68,7 @@ public static function objectBoundaries(File $file, int $position): array /** @var array> $tokens */ $tokens = $file->getTokens(); - if (!in_array(($tokens[$position]['code'] ?? null), Tokens::$ooScopeTokens, true)) { + if (! in_array(($tokens[$position]['code'] ?? null), Tokens::$ooScopeTokens, true)) { return [-1, -1]; } @@ -84,14 +84,14 @@ public static function arrayBoundaries(File $file, int $position): array { $openClose = Arrays::getOpenClose($file, $position); if ( - !is_array($openClose) - || !is_int($openClose['opener'] ?? null) - || !is_int($openClose['closer'] ?? null) + ! is_array($openClose) + || ! is_int($openClose['opener'] ?? null) + || ! is_int($openClose['closer'] ?? null) ) { return [-1, -1]; } - return [(int)$openClose['opener'], (int)$openClose['closer']]; + return [(int) $openClose['opener'], (int) $openClose['closer']]; } /** @@ -105,15 +105,15 @@ private static function startEnd(File $file, int $position): array $token = $file->getTokens()[$position] ?? []; if (($token['code'] ?? '') === T_FN) { $start = $file->findNext(T_FN_ARROW, $position + 1, null, false, null, true); - if (!$start) { + if (! $start) { return [-1, -1]; } return [$start + 1, $file->findEndOfStatement($start)]; } - $start = (int)($token['scope_opener'] ?? 0); - $end = (int)($token['scope_closer'] ?? 0); + $start = (int) ($token['scope_opener'] ?? 0); + $end = (int) ($token['scope_closer'] ?? 0); if (($start <= 0) || ($end <= 0) || ($start >= ($end - 1))) { return [-1, -1]; } diff --git a/Inpsyde/Helpers/FunctionDocBlock.php b/Inpsyde/Helpers/FunctionDocBlock.php index 0ead0cb..8574dbd 100644 --- a/Inpsyde/Helpers/FunctionDocBlock.php +++ b/Inpsyde/Helpers/FunctionDocBlock.php @@ -53,8 +53,8 @@ public static function allTags( $tokens = $file->getTokens(); if ( - !array_key_exists($position, $tokens) - || !in_array($tokens[$position]['code'], [T_FUNCTION, T_CLOSURE, T_FN], true) + ! array_key_exists($position, $tokens) + || ! in_array($tokens[$position]['code'], [T_FUNCTION, T_CLOSURE, T_FN], true) ) { return []; } @@ -62,19 +62,19 @@ public static function allTags( $closeType = T_DOC_COMMENT_CLOSE_TAG; $closeTag = $file->findPrevious($closeType, $position - 1, null, false, null, true); - if (!$closeTag || empty($tokens[$closeTag]['comment_opener'])) { + if (! $closeTag || empty($tokens[$closeTag]['comment_opener'])) { return []; } - $functionLine = (int)($tokens[$position]['line'] ?? -1); - $closeLine = (int)($tokens[$closeTag]['line'] ?? -1); + $functionLine = (int) ($tokens[$position]['line'] ?? -1); + $closeLine = (int) ($tokens[$closeTag]['line'] ?? -1); if ($closeLine !== ($functionLine - 1)) { return []; } /** @var array $tags */ $tags = []; - $start = (int)$tokens[$closeTag]['comment_opener'] + 1; + $start = (int) $tokens[$closeTag]['comment_opener'] + 1; $key = -1; $inTag = false; @@ -84,7 +84,7 @@ public static function allTags( continue; } - $content = (string)$tokens[$i]['content']; + $content = (string) $tokens[$i]['content']; if (($tokens[$i]['code'] === T_DOC_COMMENT_TAG)) { $inTag = true; $key++; @@ -102,7 +102,7 @@ public static function allTags( $rand or $rand = bin2hex(random_bytes(3)); foreach ($tags as [$tagName, $tagContent]) { empty($normalizedTags[$tagName]) and $normalizedTags[$tagName] = []; - if (!$normalizeContent) { + if (! $normalizeContent) { $normalizedTags[$tagName][] = $tagContent; continue; } @@ -140,7 +140,7 @@ public static function tag(string $tag, File $file, int $position): array public static function allParamTypes(File $file, int $functionPosition): array { $params = static::tag('@param', $file, $functionPosition); - if (!$params) { + if (! $params) { return []; } @@ -173,7 +173,7 @@ public static function normalizeTypesString(string $typesString): array $splitType = substr($splitType, 1) ?: ''; $hasNull = $hasNull || ($splitType !== ''); } - if (!$splitType) { + if (! $splitType) { continue; } if (strtolower($splitType) === 'null') { diff --git a/Inpsyde/Helpers/FunctionReturnStatement.php b/Inpsyde/Helpers/FunctionReturnStatement.php index e85405a..17939ad 100644 --- a/Inpsyde/Helpers/FunctionReturnStatement.php +++ b/Inpsyde/Helpers/FunctionReturnStatement.php @@ -76,10 +76,10 @@ public static function allInfo(File $file, int $position): array if ($tokens[$pos]['code'] === T_RETURN) { $returnCount['total']++; $void = static::isVoid($file, $pos); - $null = !$void && static::isNull($file, $pos); + $null = ! $void && static::isNull($file, $pos); $void and $returnCount['void']++; $null and $returnCount['null']++; - (!$void && !$null) and $returnCount['nonEmpty']++; + (! $void && ! $null) and $returnCount['nonEmpty']++; } $pos++; @@ -127,7 +127,7 @@ public static function isNull(File $file, int $position): bool if ($code === T_FN) { $position = $file->findNext(T_FN_ARROW, $position + 1, null, false, null, true); - if (!$position) { + if (! $position) { return false; } } diff --git a/Inpsyde/Helpers/Functions.php b/Inpsyde/Helpers/Functions.php index b6f3610..ae31eeb 100644 --- a/Inpsyde/Helpers/Functions.php +++ b/Inpsyde/Helpers/Functions.php @@ -52,14 +52,14 @@ public static function looksLikeFunctionCall(File $file, int $position): bool $types[] = T_VARIABLE; if ( - !in_array($code, $types, true) + ! in_array($code, $types, true) || (($code === T_VARIABLE) && Scopes::isOOProperty($file, $position)) ) { return false; } $callOpen = $file->findNext(Tokens::$emptyTokens, $position + 1, null, true, null, true); - if (!$callOpen || $tokens[$callOpen]['code'] !== T_OPEN_PARENTHESIS) { + if (! $callOpen || $tokens[$callOpen]['code'] !== T_OPEN_PARENTHESIS) { return false; } @@ -158,7 +158,7 @@ public static function countYieldInBody(File $file, int $position): int */ public static function isPsrMethod(File $file, int $position): bool { - if (!Scopes::isOOMethod($file, $position)) { + if (! Scopes::isOOMethod($file, $position)) { return false; } @@ -167,7 +167,7 @@ public static function isPsrMethod(File $file, int $position): bool $classPos = Conditions::getLastCondition($file, $position, $scopes); $type = is_int($classPos) ? ($tokens[$classPos]['code'] ?? null) : null; - if (!in_array($type, $scopes, true)) { + if (! in_array($type, $scopes, true)) { return false; } @@ -209,7 +209,7 @@ public static function isNonDeclarableDocBlockType(array $docTypes, bool $return // If "never" is there, this is valid for return types and PHP < 8.1, // not valid for argument types. if (in_array('never', $docTypes, true)) { - return $return && !$is81; + return $return && ! $is81; } if ($count > 1) { @@ -219,8 +219,8 @@ public static function isNonDeclarableDocBlockType(array $docTypes, bool $return } // Union type without null, valid if we're not on PHP < 8.0, or on PHP < 8.2 and // there's an intersection (DNF) - if (!in_array('null', $docTypes, true)) { - return !$is80 || (!$is82 && $isIntersection); + if (! in_array('null', $docTypes, true)) { + return ! $is80 || (! $is82 && $isIntersection); } $docTypes = array_diff($docTypes, ['null']); $count = count($docTypes); @@ -229,7 +229,7 @@ public static function isNonDeclarableDocBlockType(array $docTypes, bool $return // Union type with "null" plus something else, valid if we're not on PHP < 8.0 or // on PHP < 8.2 and there's an intersection (DNF) if ($count > 1) { - return !$is80 || (!$is82 && $isIntersection); + return ! $is80 || (! $is82 && $isIntersection); } $singleDocType = reset($docTypes); @@ -237,8 +237,8 @@ public static function isNonDeclarableDocBlockType(array $docTypes, bool $return // If the single type is "mixed" is valid if we are on PHP < 8.0. // If the single type is "null" is valid if we are on PHP < 8.2. // If the single is an intersection, is valid if we are on PHP < 8.1 - return (($singleDocType === 'mixed') && !$is80) - || (($singleDocType === 'null') && !$is82) - || ($isIntersection && !$is81); + return (($singleDocType === 'mixed') && ! $is80) + || (($singleDocType === 'null') && ! $is82) + || ($isIntersection && ! $is81); } } diff --git a/Inpsyde/Helpers/Misc.php b/Inpsyde/Helpers/Misc.php index dbb66f7..0299a8d 100644 --- a/Inpsyde/Helpers/Misc.php +++ b/Inpsyde/Helpers/Misc.php @@ -43,7 +43,7 @@ final class Misc public static function minPhpTestVersion(): string { $testVersion = trim(Config::getConfigData('testVersion') ?: ''); - if (!$testVersion) { + if (! $testVersion) { return self::MIN_SUPPORTED_VERSION; } @@ -107,8 +107,8 @@ public static function filterTokensByType( continue; } $empty = $types === []; - $inArray = !$empty && in_array($token['code'] ?? '', $types, true); - if ($empty || (!$excludeTypes && $inArray) || ($excludeTypes && !$inArray)) { + $inArray = ! $empty && in_array($token['code'] ?? '', $types, true); + if ($empty || (! $excludeTypes && $inArray) || ($excludeTypes && ! $inArray)) { $filtered[$i] = $token; } } @@ -136,7 +136,7 @@ public static function tokensSubsetToString( $content = ''; foreach ($filtered as $token) { - $content .= (string)($token['content'] ?? ''); + $content .= (string) ($token['content'] ?? ''); } return $content; diff --git a/Inpsyde/Helpers/Names.php b/Inpsyde/Helpers/Names.php index ad2b8ce..f091af8 100644 --- a/Inpsyde/Helpers/Names.php +++ b/Inpsyde/Helpers/Names.php @@ -62,12 +62,12 @@ public static function nameableTokenName(File $file, int $position): ?string $tokens = $file->getTokens(); $code = $tokens[$position]['code'] ?? null; - if (!in_array($code, self::NAMEABLE_TOKENS, true)) { + if (! in_array($code, self::NAMEABLE_TOKENS, true)) { return null; } if ($code === T_VARIABLE) { - $name = ltrim((string)($tokens[$position]['content'] ?? ''), '$'); + $name = ltrim((string) ($tokens[$position]['content'] ?? ''), '$'); return ($name === '') ? null : $name; } @@ -79,7 +79,7 @@ public static function nameableTokenName(File $file, int $position): ?string } $namePosition = $file->findNext(T_STRING, $position, null, false, null, true); - $name = ($namePosition === false) ? null : (string)$tokens[$namePosition]['content']; + $name = ($namePosition === false) ? null : (string) $tokens[$namePosition]['content']; return ($name === '') ? null : $name; } diff --git a/Inpsyde/Helpers/Objects.php b/Inpsyde/Helpers/Objects.php index e84084d..d6ffad8 100644 --- a/Inpsyde/Helpers/Objects.php +++ b/Inpsyde/Helpers/Objects.php @@ -47,7 +47,7 @@ public static function countProperties(File $file, int $position): int /** @var array> $tokens */ $tokens = $file->getTokens(); if ( - !in_array( + ! in_array( $tokens[$position]['code'] ?? null, Collections::ooPropertyScopes(), true @@ -100,16 +100,16 @@ public static function findAllImportUses(File $file, int $position): array while (true) { $nextUse = $file->findNext(T_USE, $nextUse + 1, $position - 1); - if (!$nextUse) { + if (! $nextUse) { break; } - if (!UseStatements::isImportUse($file, $nextUse)) { + if (! UseStatements::isImportUse($file, $nextUse)) { continue; } $usePositions[] = $nextUse; } - if (!$usePositions) { + if (! $usePositions) { return []; } @@ -148,12 +148,12 @@ public static function allInterfacesFullyQualifiedNames(File $file, int $positio { $tokens = $file->getTokens(); $code = $tokens[$position]['code'] ?? null; - if (!in_array($code, Collections::ooCanImplement(), true)) { + if (! in_array($code, Collections::ooCanImplement(), true)) { return null; } $implementsPos = $file->findNext(T_IMPLEMENTS, $position, null, false, null, true); - if (!$implementsPos) { + if (! $implementsPos) { return null; } @@ -166,14 +166,14 @@ public static function allInterfacesFullyQualifiedNames(File $file, int $positio true ); - if (!$namesEnd) { + if (! $namesEnd) { return null; } $uses = static::findAllImportUses($file, $position - 1); /** @var non-empty-list|false $names */ $names = ObjectDeclarations::findImplementedInterfaceNames($file, $position); - if (!$names) { + if (! $names) { return []; } diff --git a/Inpsyde/Helpers/WpHooks.php b/Inpsyde/Helpers/WpHooks.php index d8e56c0..cd0888c 100644 --- a/Inpsyde/Helpers/WpHooks.php +++ b/Inpsyde/Helpers/WpHooks.php @@ -49,7 +49,7 @@ public static function isHookClosure( /** @var array> $tokens */ $tokens = $file->getTokens(); - if (!in_array(($tokens[$position]['code'] ?? ''), [T_CLOSURE, T_FN], true)) { + if (! in_array(($tokens[$position]['code'] ?? ''), [T_CLOSURE, T_FN], true)) { return false; } @@ -58,18 +58,18 @@ public static function isHookClosure( $exclude = $empty; $exclude[] = T_STATIC; $commaPos = $file->findPrevious($exclude, $position - 1, null, true, null, true); - if (!$commaPos || ($tokens[$commaPos]['code'] ?? '') !== T_COMMA) { + if (! $commaPos || ($tokens[$commaPos]['code'] ?? '') !== T_COMMA) { return false; } $openType = [T_OPEN_PARENTHESIS]; $openCallPos = $file->findPrevious($openType, $commaPos - 2, null, false, null, true); - if (!$openCallPos) { + if (! $openCallPos) { return false; } $functionCallPos = $file->findPrevious($empty, $openCallPos - 1, null, true, null, true); - if (!$functionCallPos || $tokens[$functionCallPos]['code'] !== T_STRING) { + if (! $functionCallPos || $tokens[$functionCallPos]['code'] !== T_STRING) { return false; } @@ -87,6 +87,6 @@ public static function isHookClosure( */ public static function isHookFunction(File $file, int $position): bool { - return (bool)FunctionDocBlock::tag('@wp-hook', $file, $position); + return (bool) FunctionDocBlock::tag('@wp-hook', $file, $position); } } diff --git a/Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php b/Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php index 0bc51f1..0e4742e 100644 --- a/Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php @@ -80,12 +80,12 @@ public function process(File $phpcsFile, $stackPtr): void } $docTypes = $docBlockTypes[$parameter['name']] ?? []; - if (!Functions::isNonDeclarableDocBlockType($docTypes, false)) { + if (! Functions::isNonDeclarableDocBlockType($docTypes, false)) { $errors[] = $parameter['name']; } } - if (!$errors) { + if (! $errors) { return; } diff --git a/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php b/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php index 261a5a1..bea71b2 100644 --- a/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/DisableMagicSerializeSniff.php @@ -61,7 +61,7 @@ public function register(): array public function process(File $phpcsFile, $stackPtr): void { // phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration - if (!Scopes::isOOMethod($phpcsFile, $stackPtr)) { + if (! Scopes::isOOMethod($phpcsFile, $stackPtr)) { return; } diff --git a/Inpsyde/Sniffs/CodeQuality/ForbiddenPublicPropertySniff.php b/Inpsyde/Sniffs/CodeQuality/ForbiddenPublicPropertySniff.php index d3941c8..862172c 100644 --- a/Inpsyde/Sniffs/CodeQuality/ForbiddenPublicPropertySniff.php +++ b/Inpsyde/Sniffs/CodeQuality/ForbiddenPublicPropertySniff.php @@ -54,7 +54,7 @@ public function process(File $phpcsFile, $stackPtr): void { // phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration - if (!Scopes::isOOProperty($phpcsFile, $stackPtr)) { + if (! Scopes::isOOProperty($phpcsFile, $stackPtr)) { return; } @@ -82,7 +82,7 @@ private function isSniffClass(File $file, int $position): bool { $classNameTokenPosition = $file->findNext( T_STRING, - (int)$file->findPrevious(T_CLASS, $position) + (int) $file->findPrevious(T_CLASS, $position) ); if ($classNameTokenPosition === false) { @@ -93,7 +93,7 @@ private function isSniffClass(File $file, int $position): bool $tokens = $file->getTokens(); $classNameToken = $tokens[$classNameTokenPosition]; - if (substr((string)$classNameToken['content'], -5, 5) === 'Sniff') { + if (substr((string) $classNameToken['content'], -5, 5) === 'Sniff') { return true; } diff --git a/Inpsyde/Sniffs/CodeQuality/FunctionBodyStartSniff.php b/Inpsyde/Sniffs/CodeQuality/FunctionBodyStartSniff.php index 78b2569..55c867b 100644 --- a/Inpsyde/Sniffs/CodeQuality/FunctionBodyStartSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/FunctionBodyStartSniff.php @@ -57,8 +57,8 @@ public function process(File $phpcsFile, $stackPtr): void $tokens = $phpcsFile->getTokens(); $token = $tokens[$stackPtr] ?? []; - $scopeOpener = (int)($token['scope_opener'] ?? -1); - $scopeCloser = (int)($token['scope_closer'] ?? -1); + $scopeOpener = (int) ($token['scope_opener'] ?? -1); + $scopeCloser = (int) ($token['scope_closer'] ?? -1); if ($scopeOpener < 0 || $scopeCloser < 0 || $scopeCloser <= $scopeOpener) { return; @@ -66,8 +66,8 @@ public function process(File $phpcsFile, $stackPtr): void $bodyStart = $phpcsFile->findNext([T_WHITESPACE], $scopeOpener + 1, null, true); if ( - !$bodyStart - || !array_key_exists($bodyStart, $tokens) + ! $bodyStart + || ! array_key_exists($bodyStart, $tokens) || $bodyStart <= $scopeOpener || $bodyStart >= $scopeCloser ) { @@ -76,8 +76,8 @@ public function process(File $phpcsFile, $stackPtr): void [$code, $message, $expectedLine] = $this->checkBodyStart( $bodyStart, - (int)($tokens[$scopeOpener]['line'] ?? -1), - (int)($token['line'] ?? -1), + (int) ($tokens[$scopeOpener]['line'] ?? -1), + (int) ($token['line'] ?? -1), $phpcsFile ); @@ -107,7 +107,7 @@ private function checkBodyStart( /** @var array> $tokens */ $tokens = $file->getTokens(); - $bodyLine = (int)($tokens[$bodyStart]['line'] ?? -1); + $bodyLine = (int) ($tokens[$bodyStart]['line'] ?? -1); $isMultiLineDeclare = ($openerLine - $functionLine) > 1; $isSingleLineDeclare = $openerLine === ($functionLine + 1); @@ -117,13 +117,13 @@ private function checkBodyStart( ($isMultiLineDeclare || $isSingleLineSignature) && $bodyLine !== ($openerLine + 2) || $isSingleLineDeclare && $bodyLine > ($openerLine + 2); - if (!$error) { + if (! $error) { return [null, null, null]; } $startWithComment = in_array($tokens[$bodyStart]['code'], Tokens::$emptyTokens, true); - if (!$startWithComment && ($isMultiLineDeclare || $isSingleLineSignature)) { + if (! $startWithComment && ($isMultiLineDeclare || $isSingleLineSignature)) { $where = $isSingleLineSignature ? 'with single-line signature and open curly bracket on same line' : 'where arguments declaration spans across multiple lines'; @@ -138,7 +138,7 @@ private function checkBodyStart( ]; } - if (!$isSingleLineDeclare) { + if (! $isSingleLineDeclare) { return [null, null, null]; } @@ -163,7 +163,7 @@ private function fix(int $bodyStart, int $expectedLine, int $scopeOpener, File $ { /** @var array> $tokens */ $tokens = $file->getTokens(); - $currentLine = (int)($tokens[$bodyStart]['line'] ?? -1); + $currentLine = (int) ($tokens[$bodyStart]['line'] ?? -1); if ($currentLine === $expectedLine) { return; diff --git a/Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php b/Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php index b571036..b5f3973 100644 --- a/Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php @@ -97,15 +97,15 @@ private function structureLinesCount(File $file, int $position): int $token = $tokens[$position] ?? []; if ( - !array_key_exists('scope_opener', $token) - || !array_key_exists('scope_closer', $token) + ! array_key_exists('scope_opener', $token) + || ! array_key_exists('scope_closer', $token) ) { return 0; } - $start = (int)$token['scope_opener']; - $end = (int)$token['scope_closer']; - $length = (int)$tokens[$end]['line'] - (int)$tokens[$start]['line']; + $start = (int) $token['scope_opener']; + $end = (int) $token['scope_closer']; + $length = (int) $tokens[$end]['line'] - (int) $tokens[$start]['line']; if ($length < $this->maxLength) { return $length; @@ -138,7 +138,7 @@ private function collectLinesToExclude(int $start, int $end, array $tokens): int $empty = array_filter(array_column($linesData, 'empty')); $onlyComment = array_filter(array_column($linesData, 'only-comment')); - $toExcludeCount = (int)array_sum($docblocks); + $toExcludeCount = (int) array_sum($docblocks); if ($this->ignoreBlankLines) { $toExcludeCount += count($empty); } @@ -156,12 +156,12 @@ private function collectLinesToExclude(int $start, int $end, array $tokens): int */ private function ignoredLinesData(array $token, array $lines): array { - $line = (int)$token['line']; - if (!array_key_exists($line, $lines)) { + $line = (int) $token['line']; + if (! array_key_exists($line, $lines)) { $lines[$line] = ['empty' => true, 'only-comment' => true]; } - if (!in_array($token['code'], [T_COMMENT, T_WHITESPACE], true)) { + if (! in_array($token['code'], [T_COMMENT, T_WHITESPACE], true)) { $lines[$line]['only-comment'] = false; } @@ -181,7 +181,7 @@ private function ignoredLinesData(array $token, array $lines): array private function docBlocksData(array $tokens, int $position, array $docBlocks): array { if ( - !$this->ignoreDocBlocks + ! $this->ignoreDocBlocks || $tokens[$position]['code'] !== T_DOC_COMMENT_OPEN_TAG ) { return $docBlocks; @@ -189,7 +189,7 @@ private function docBlocksData(array $tokens, int $position, array $docBlocks): $closer = $tokens[$position]['comment_closer'] ?? null; $docBlocks[] = is_numeric($closer) - ? 1 + ((int)$tokens[(int)$closer]['line'] - (int)$tokens[$position]['line']) + ? 1 + ((int) $tokens[(int) $closer]['line'] - (int) $tokens[$position]['line']) : 1; return $docBlocks; @@ -208,7 +208,7 @@ private function normalizeIgnoreFlags(): void foreach ($flags as $flag) { if (is_string($this->{$flag})) { - $this->{$flag} = (bool)filter_var($this->{$flag}, FILTER_VALIDATE_BOOLEAN); + $this->{$flag} = (bool) filter_var($this->{$flag}, FILTER_VALIDATE_BOOLEAN); } } } diff --git a/Inpsyde/Sniffs/CodeQuality/HookClosureReturnSniff.php b/Inpsyde/Sniffs/CodeQuality/HookClosureReturnSniff.php index 5092a09..974060d 100644 --- a/Inpsyde/Sniffs/CodeQuality/HookClosureReturnSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/HookClosureReturnSniff.php @@ -55,7 +55,7 @@ public function process(File $phpcsFile, $stackPtr): void { // phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration - if (!WpHooks::isHookClosure($phpcsFile, $stackPtr)) { + if (! WpHooks::isHookClosure($phpcsFile, $stackPtr)) { return; } @@ -74,7 +74,7 @@ public function process(File $phpcsFile, $stackPtr): void $isFilterClosure = WpHooks::isHookClosure($phpcsFile, $stackPtr, true, false); - if ($isFilterClosure && (!$nonVoidReturnCount || $voidReturnCount)) { + if ($isFilterClosure && (! $nonVoidReturnCount || $voidReturnCount)) { $phpcsFile->addError( 'No (or void) return from filter closure.', $stackPtr, @@ -82,7 +82,7 @@ public function process(File $phpcsFile, $stackPtr): void ); } - if (!$isFilterClosure && $nonVoidReturnCount) { + if (! $isFilterClosure && $nonVoidReturnCount) { $phpcsFile->addError( 'Return value from action closure.', $stackPtr, diff --git a/Inpsyde/Sniffs/CodeQuality/LineLengthSniff.php b/Inpsyde/Sniffs/CodeQuality/LineLengthSniff.php index 3869360..3cd8dfe 100644 --- a/Inpsyde/Sniffs/CodeQuality/LineLengthSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/LineLengthSniff.php @@ -76,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr): int // phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration $longLinesData = $this->collectLongLinesData($phpcsFile, max(1, $stackPtr)); - if (!$longLinesData) { + if (! $longLinesData) { return $phpcsFile->numTokens + 1; } @@ -113,7 +113,7 @@ private function collectLongLinesData(File $file, int $start): array for ($i = $start; $i < $file->numTokens; $i++) { // Still processing previous line: increment length and continue. if ($lastLine && ($tokens[$i]['line'] === $lastLine)) { - $content = (string)$tokens[$i]['content']; + $content = (string) $tokens[$i]['content']; $data[$lastLine]['length'] += strlen($content); $data[$lastLine]['nonEmptyLength'] += strlen(trim($content)); continue; @@ -124,8 +124,8 @@ private function collectLongLinesData(File $file, int $start): array $data[$lastLine]['end'] = $i - 1; } - $lastLine = (int)$tokens[$i]['line']; - $content = (string)$tokens[$i]['content']; + $lastLine = (int) $tokens[$i]['line']; + $content = (string) $tokens[$i]['content']; $data[$lastLine] = [ 'length' => strlen($content), 'nonEmptyLength' => strlen(trim($content)), @@ -177,7 +177,7 @@ private function isLongWord(File $file, array $tokens, int $start, int $end): bo $foundString = false; while ($start && ($start <= $end)) { - if (!in_array($tokens[$start]['code'], $targetTypes, true)) { + if (! in_array($tokens[$start]['code'], $targetTypes, true)) { $start++; continue; } @@ -192,7 +192,7 @@ private function isLongWord(File $file, array $tokens, int $start, int $end): bo ? $this->isLongHtmlAttribute($start, $end, $file, $tokens) : $this->isLongSingleWord($start, $end, $file, $tokens); - if (!$isLong) { + if (! $isLong) { return false; } @@ -224,11 +224,11 @@ private function isLongHtmlAttribute( $content = ''; for ($i = $position; $i <= $lineEnd; $i++) { $code = $tokens[$i]['code']; - if (($code === T_OPEN_TAG || $code === T_OPEN_TAG_WITH_ECHO) && !$inPhp) { + if (($code === T_OPEN_TAG || $code === T_OPEN_TAG_WITH_ECHO) && ! $inPhp) { $inPhp = true; } if ($tokens[$i]['code'] === T_INLINE_HTML || $inPhp) { - $tokenContent = (string)$tokens[$i]['content']; + $tokenContent = (string) $tokens[$i]['content']; $content .= $inPhp ? str_repeat('x', strlen($tokenContent)) : $tokenContent; } if ($tokens[$i]['code'] === T_CLOSE_TAG && $inPhp) { @@ -271,7 +271,12 @@ private function isLongSingleWord( array $tokens ): bool { - $words = preg_split('~\s+~', (string)$tokens[$position]['content'], 2, PREG_SPLIT_NO_EMPTY); + $words = preg_split( + '~\s+~', + (string) $tokens[$position]['content'], + 2, + PREG_SPLIT_NO_EMPTY + ); // If multiple words exceed line limit, we can split each word in its own line if ($words === false || count($words) !== 1) { @@ -281,7 +286,7 @@ private function isLongSingleWord( $word = reset($words); $firstNonWhitePos = $file->findNext(T_WHITESPACE, $position, $lineEnd, true); $firstNonWhite = ($firstNonWhitePos === false) ? null : $tokens[$firstNonWhitePos]; - $tolerance = is_array($firstNonWhite) ? ((int)($firstNonWhite['column'] ?? 1) + 3) : 4; + $tolerance = is_array($firstNonWhite) ? ((int) ($firstNonWhite['column'] ?? 1) + 3) : 4; return (strlen($word) + $tolerance) > $this->lineLimit; } @@ -320,8 +325,8 @@ private function isLongI10nFunction(File $file, array $tokens, int $start, int $ return false; } - $function = strtolower((string)$tokens[$functionPos]['content']); - if (!in_array($function, self::I18N_FUNCTIONS, true)) { + $function = strtolower((string) $tokens[$functionPos]['content']); + if (! in_array($function, self::I18N_FUNCTIONS, true)) { return false; } @@ -333,7 +338,7 @@ private function isLongI10nFunction(File $file, array $tokens, int $start, int $ if ($tokens[$i]['line'] !== $targetLine) { continue; } - $textLen += max(1, strlen((string)$tokens[$i]['content'])); + $textLen += max(1, strlen((string) $tokens[$i]['content'])); } return ($textLen + 2) > $this->lineLimit; @@ -360,7 +365,7 @@ private function isLongUse(File $file, array $tokens, int $start, int $end): boo $endUse = $file->findEndOfStatement($usePos); $useLen = 0; for ($i = $usePos; $i <= $endUse; $i++) { - $useLen += strlen((string)$tokens[$i]['content']); + $useLen += strlen((string) $tokens[$i]['content']); } return $useLen > $this->lineLimit; diff --git a/Inpsyde/Sniffs/CodeQuality/NestingLevelSniff.php b/Inpsyde/Sniffs/CodeQuality/NestingLevelSniff.php index f8adbd8..ef7be5b 100644 --- a/Inpsyde/Sniffs/CodeQuality/NestingLevelSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/NestingLevelSniff.php @@ -64,10 +64,10 @@ public function process(File $phpcsFile, $stackPtr): void return; } - $start = (int)$tokens[$stackPtr]['scope_opener']; - $end = (int)$tokens[$stackPtr]['scope_closer']; + $start = (int) $tokens[$stackPtr]['scope_opener']; + $end = (int) $tokens[$stackPtr]['scope_closer']; - $baseLevel = (int)$tokens[$stackPtr]['level']; + $baseLevel = (int) $tokens[$stackPtr]['level']; $nestingLevel = 0; $inTry = false; $endTry = null; @@ -82,9 +82,9 @@ public function process(File $phpcsFile, $stackPtr): void continue; } - $level = (int)$tokens[$i]['level']; + $level = (int) $tokens[$i]['level']; - if (!$inTry && $tokens[$i]['code'] === T_TRY && $level === $tryTargetLevel) { + if (! $inTry && $tokens[$i]['code'] === T_TRY && $level === $tryTargetLevel) { $inTry = true; continue; } @@ -123,9 +123,9 @@ public function process(File $phpcsFile, $stackPtr): void private function maybeTrigger(int $nestingLevel, File $phpcsFile, int $stackPtr): void { $isError = $nestingLevel >= $this->errorLimit; - $isWarning = !$isError && ($nestingLevel >= $this->warningLimit); + $isWarning = ! $isError && ($nestingLevel >= $this->warningLimit); - if (!$isError && !$isWarning) { + if (! $isError && ! $isWarning) { return; } @@ -149,7 +149,7 @@ private function endOfTryBlock(int $catchPosition, File $phpcsFile): int { /** @var array> $tokens */ $tokens = $phpcsFile->getTokens(); - $currentEnd = (int)$tokens[$catchPosition]['scope_closer']; + $currentEnd = (int) $tokens[$catchPosition]['scope_closer']; $nextCatch = $phpcsFile->findNext(T_CATCH, $currentEnd + 1, $currentEnd + 3); if ($nextCatch) { return $this->endOfTryBlock($nextCatch, $phpcsFile); @@ -157,6 +157,6 @@ private function endOfTryBlock(int $catchPosition, File $phpcsFile): int $finally = $phpcsFile->findNext(T_FINALLY, $currentEnd + 1, $currentEnd + 3); - return $finally ? (int)$tokens[$finally]['scope_closer'] + 1 : $currentEnd + 1; + return $finally ? (int) $tokens[$finally]['scope_closer'] + 1 : $currentEnd + 1; } } diff --git a/Inpsyde/Sniffs/CodeQuality/NoAccessorsSniff.php b/Inpsyde/Sniffs/CodeQuality/NoAccessorsSniff.php index ec75161..3802836 100644 --- a/Inpsyde/Sniffs/CodeQuality/NoAccessorsSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/NoAccessorsSniff.php @@ -67,12 +67,12 @@ public function process(File $phpcsFile, $stackPtr): void // phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration // phpcs:enable Inpsyde.CodeQuality.FunctionLength - if (!Scopes::isOOMethod($phpcsFile, $stackPtr)) { + if (! Scopes::isOOMethod($phpcsFile, $stackPtr)) { return; } $functionName = $phpcsFile->getDeclarationName($stackPtr); - if (!$functionName || in_array($functionName, self::ALLOWED_NAMES, true)) { + if (! $functionName || in_array($functionName, self::ALLOWED_NAMES, true)) { return; } @@ -91,7 +91,7 @@ public function process(File $phpcsFile, $stackPtr): void $modifierPointer = $tokens[$modifierPointerPosition] ?? null; if ( $modifierPointer - && !in_array($modifierPointer['code'], Tokens::$scopeModifiers, true) + && ! in_array($modifierPointer['code'], Tokens::$scopeModifiers, true) ) { $modifierPointer = null; } @@ -106,7 +106,7 @@ public function process(File $phpcsFile, $stackPtr): void } preg_match('/^(set|get)[_A-Z0-9]+/', $functionName, $matches); - if (!$matches) { + if (! $matches) { return; } diff --git a/Inpsyde/Sniffs/CodeQuality/NoRootNamespaceFunctionsSniff.php b/Inpsyde/Sniffs/CodeQuality/NoRootNamespaceFunctionsSniff.php index f4c9cdb..48b5af9 100644 --- a/Inpsyde/Sniffs/CodeQuality/NoRootNamespaceFunctionsSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/NoRootNamespaceFunctionsSniff.php @@ -63,7 +63,7 @@ public function process(File $phpcsFile, $stackPtr): void return; } $name = FunctionDeclarations::getName($phpcsFile, $stackPtr); - if (!$name) { + if (! $name) { return; } diff --git a/Inpsyde/Sniffs/CodeQuality/NoTopLevelDefineSniff.php b/Inpsyde/Sniffs/CodeQuality/NoTopLevelDefineSniff.php index 895c166..deeba47 100644 --- a/Inpsyde/Sniffs/CodeQuality/NoTopLevelDefineSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/NoTopLevelDefineSniff.php @@ -59,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr): void if ( ($tokens[$stackPtr]['content'] ?? '') !== 'define' || ($tokens[$stackPtr]['level'] ?? -1) !== 0 - || !Functions::looksLikeFunctionCall($phpcsFile, $stackPtr) + || ! Functions::looksLikeFunctionCall($phpcsFile, $stackPtr) ) { return; } diff --git a/Inpsyde/Sniffs/CodeQuality/Psr4Sniff.php b/Inpsyde/Sniffs/CodeQuality/Psr4Sniff.php index 3368a34..4722a07 100644 --- a/Inpsyde/Sniffs/CodeQuality/Psr4Sniff.php +++ b/Inpsyde/Sniffs/CodeQuality/Psr4Sniff.php @@ -69,7 +69,7 @@ public function process(File $phpcsFile, $stackPtr): void $this->normalizeExcluded(); - if (!$this->psr4) { + if (! $this->psr4) { $this->checkFilenameOnly($phpcsFile, $stackPtr, $className, $entityType); return; @@ -128,7 +128,7 @@ private function checkPsr4( $fullyQualifiedName = $namespace . "\\{$className}"; foreach ($this->exclude as $excluded) { - if (strpos($fullyQualifiedName, (string)$excluded) === 0) { + if (strpos($fullyQualifiedName, (string) $excluded) === 0) { return; } } @@ -136,7 +136,7 @@ private function checkPsr4( $filePath = str_replace('\\', '/', $file->getFilename()); foreach ($this->psr4 as $baseNamespace => $foldersStr) { - if (!is_string($baseNamespace) || !is_string($foldersStr)) { + if (! is_string($baseNamespace) || ! is_string($foldersStr)) { continue; } diff --git a/Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php b/Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php index 3fb9591..c421b3a 100644 --- a/Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/ReturnTypeDeclarationSniff.php @@ -80,7 +80,7 @@ public function process(File $phpcsFile, $stackPtr): void $tokens = $phpcsFile->getTokens(); $data = FunctionDeclarations::getProperties($phpcsFile, $stackPtr); - if (!$data['has_body']) { + if (! $data['has_body']) { return; } @@ -104,8 +104,8 @@ public function process(File $phpcsFile, $stackPtr): void : []; if ( - !Functions::isNonDeclarableDocBlockType($docTypes, true) - && !$this->shouldIgnore($phpcsFile, $stackPtr, $tokens) + ! Functions::isNonDeclarableDocBlockType($docTypes, true) + && ! $this->shouldIgnore($phpcsFile, $stackPtr, $tokens) ) { $phpcsFile->addWarning('Return type is missing', $stackPtr, 'NoReturnType'); @@ -234,8 +234,8 @@ private function checkIncorrectVoid( $hasReturnNull = $returnInfo['null'] > 0; if ( - ($hasReturnNull && !in_array('null', $returnTypes, true)) - || (!in_array('void', $returnTypes, true) && ($returnInfo['void'] > 0)) + ($hasReturnNull && ! in_array('null', $returnTypes, true)) + || (! in_array('void', $returnTypes, true) && ($returnInfo['void'] > 0)) ) { $file->addError( sprintf( @@ -306,7 +306,7 @@ private function checkInvalidGenerator( ): bool { $hasGenerator = false; - while (!$hasGenerator && $returnTypes) { + while (! $hasGenerator && $returnTypes) { $returnType = explode('&', rtrim(ltrim(array_shift($returnTypes), '('), ')')); $hasGenerator = in_array('Generator', $returnType, true) || in_array('\Generator', $returnType, true) @@ -342,7 +342,7 @@ private function checkInvalidGenerator( return true; } - if (!$hasGenerator && ($yieldCount > 0)) { + if (! $hasGenerator && ($yieldCount > 0)) { $file->addError( 'Return type does not contain "Generator" but yield found in the function body', $position, diff --git a/Inpsyde/Sniffs/CodeQuality/StaticClosureSniff.php b/Inpsyde/Sniffs/CodeQuality/StaticClosureSniff.php index d8a80c0..5eaf0cb 100644 --- a/Inpsyde/Sniffs/CodeQuality/StaticClosureSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/StaticClosureSniff.php @@ -69,9 +69,9 @@ public function process(File $phpcsFile, $stackPtr): void /** @var array> $tokens */ $tokens = $phpcsFile->getTokens(); - while (!$thisFound && ($i < $functionEnd)) { + while (! $thisFound && ($i < $functionEnd)) { $token = $tokens[$i]; - $content = (string)($token['content'] ?? ''); + $content = (string) ($token['content'] ?? ''); $thisFound = (($token['code'] === T_VARIABLE) && ($content === '$this')) || ( in_array($token['code'], [T_DOUBLE_QUOTED_STRING, T_HEREDOC], true) @@ -96,7 +96,7 @@ public function process(File $phpcsFile, $stackPtr): void } } - $line = (int)$tokens[$stackPtr]['line']; + $line = (int) $tokens[$stackPtr]['line']; $message = sprintf('Closure found at line %d could be static.', $line); if ($phpcsFile->addFixableWarning($message, $stackPtr, 'PossiblyStaticClosure')) { diff --git a/Inpsyde/Sniffs/CodeQuality/VariablesNameSniff.php b/Inpsyde/Sniffs/CodeQuality/VariablesNameSniff.php index 88a4945..57cc5e1 100644 --- a/Inpsyde/Sniffs/CodeQuality/VariablesNameSniff.php +++ b/Inpsyde/Sniffs/CodeQuality/VariablesNameSniff.php @@ -98,7 +98,7 @@ public function process(File $phpcsFile, $stackPtr): void /** @var array> $tokens */ $tokens = $phpcsFile->getTokens(); - $name = (string)$tokens[$stackPtr]['content']; + $name = (string) $tokens[$stackPtr]['content']; if ( in_array($name, $ignored, true) @@ -119,7 +119,7 @@ public function process(File $phpcsFile, $stackPtr): void if ( ($isProperty && $this->arePropertiesIgnored()) - || (!$isProperty && $this->areVariablesIgnored()) + || (! $isProperty && $this->areVariablesIgnored()) ) { return; } @@ -152,7 +152,7 @@ private function checkType(): string */ private function arePropertiesIgnored(): bool { - return (bool)filter_var($this->ignoreProperties, FILTER_VALIDATE_BOOLEAN); + return (bool) filter_var($this->ignoreProperties, FILTER_VALIDATE_BOOLEAN); } /** @@ -160,7 +160,7 @@ private function arePropertiesIgnored(): bool */ private function areVariablesIgnored(): bool { - return (bool)filter_var($this->ignoreLocalVars, FILTER_VALIDATE_BOOLEAN); + return (bool) filter_var($this->ignoreLocalVars, FILTER_VALIDATE_BOOLEAN); } /** @@ -170,7 +170,7 @@ private function areVariablesIgnored(): bool private function checkCamelCase(string $name): bool { return preg_match('~^\$[a-z]+(?:[a-zA-Z0-9]+)?$~', $name) - && !preg_match('~[A-Z]{2,}~', $name); + && ! preg_match('~[A-Z]{2,}~', $name); } /** @@ -179,7 +179,7 @@ private function checkCamelCase(string $name): bool */ private function checkSnakeCase(string $name): bool { - return (bool)preg_match('~^\$[a-z]+(?:[a-z0-9_]+)?$~', $name); + return (bool) preg_match('~^\$[a-z]+(?:[a-z0-9_]+)?$~', $name); } /** diff --git a/tests/cases/FixturesTest.php b/tests/cases/FixturesTest.php index d8d7631..da5ccc6 100644 --- a/tests/cases/FixturesTest.php +++ b/tests/cases/FixturesTest.php @@ -61,7 +61,7 @@ public function testAllFixtures(string $fixtureFile): void $previous = null; foreach ($failures as $failure) { - if (!$failure instanceof \Throwable) { + if (! $failure instanceof \Throwable) { continue; } @@ -211,7 +211,7 @@ private function createPhpcsForFixture( $sniffFile = str_replace('.', '/', "{$sniffName}Sniff"); $sniffPath = getenv('SNIFFS_PATH') . "/{$sniffFile}.php"; - if (!file_exists($sniffPath) || !is_readable($sniffPath)) { + if (! file_exists($sniffPath) || ! is_readable($sniffPath)) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped throw new Exception("Non-existent of unreadable sniff file '{$sniffPath}' found."); } diff --git a/tests/src/FixtureContentParser.php b/tests/src/FixtureContentParser.php index 42de807..d05b5a3 100644 --- a/tests/src/FixtureContentParser.php +++ b/tests/src/FixtureContentParser.php @@ -42,21 +42,21 @@ class FixtureContentParser */ public function parse(string $fixturePath): array { - if (!file_exists($fixturePath) || !is_readable($fixturePath)) { + if (! file_exists($fixturePath) || ! is_readable($fixturePath)) { throw new \Error("Fixture file {$fixturePath} is not readable."); } - $accumulator = (object)[ + $accumulator = (object) [ 'sniff' => null, 'warnings' => [], 'errors' => [], 'messages' => [], - 'properties' => (object)[ + 'properties' => (object) [ 'start' => false, 'end' => false, 'values' => [], ], - 'process' => (object)[ + 'process' => (object) [ 'start' => false, 'end' => false, 'content' => '', @@ -77,7 +77,7 @@ public function parse(string $fixturePath): array */ private function processResults(object $accumulator, string $fixturePath): array { - if (!$accumulator->process->content) { + if (! $accumulator->process->content) { return [ $this->checkSniffName($accumulator->sniff), new SniffMessages( @@ -106,11 +106,11 @@ private function processResults(object $accumulator, string $fixturePath): array [$sniff, $messages, $warnings, $errors, $properties] = $results; if ( - !is_string($sniff) - || !is_array($messages) - || !is_array($warnings) - || !is_array($errors) - || !is_array($properties) + ! is_string($sniff) + || ! is_array($messages) + || ! is_array($warnings) + || ! is_array($errors) + || ! is_array($properties) ) { throw new \Error( sprintf( @@ -140,12 +140,12 @@ private function checkSniffName(?string $sniff): string } static $regex; - if (!$regex) { + if (! $regex) { $chars = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'; $regex = "({$chars})(({$chars}|\.)*({$chars}))"; } - if (!preg_match('~^' . $regex . '$~', $sniff)) { + if (! preg_match('~^' . $regex . '$~', $sniff)) { throw new \Error("Invalid sniff name '{$sniff}'."); } @@ -182,9 +182,9 @@ private function readFile(string $file): \Generator private function readLine(int $lineNum, string $line, object $accumulator): void { if ( - !$this->readProcessLine($lineNum, $line, $accumulator) - && !$this->readSniffLine($line, $accumulator) - && !$this->readPropertiesLine($lineNum, $line, $accumulator) + ! $this->readProcessLine($lineNum, $line, $accumulator) + && ! $this->readSniffLine($line, $accumulator) + && ! $this->readPropertiesLine($lineNum, $line, $accumulator) ) { $this->readTokenLine($lineNum, $line, $accumulator); } @@ -235,7 +235,7 @@ private function readSniffLine(string $line, object $accumulator): bool $regex or $regex = '~' . preg_quote(self::TOKEN_SNIFF, '~') . '\s+([^\s]+)~'; preg_match($regex, $line, $matches); - if (!empty($matches[1])) { + if (! empty($matches[1])) { $accumulator->sniff = $matches[1]; return true; @@ -288,7 +288,7 @@ private function readPropertiesLine(int $lineNum, string $line, object $accumula private function readTokenLine(int $lineNum, string $line, object $accumulator): void { static $pattern; - if (!$pattern) { + if (! $pattern) { $typePattern = '(?Warning|Error|Message)'; $hasCodePattern = '(?Code)?'; @@ -298,7 +298,7 @@ private function readTokenLine(int $lineNum, string $line, object $accumulator): } preg_match("~{$pattern}~", $line, $matches); - if (!$matches) { + if (! $matches) { return; } @@ -313,7 +313,7 @@ private function readTokenLine(int $lineNum, string $line, object $accumulator): } $code = ''; - if (!empty($matches['has_code']) && !empty($matches['code'])) { + if (! empty($matches['has_code']) && ! empty($matches['code'])) { $matchedCode = trim($matches['code']); $matchedCode and $code = $matchedCode; }