Dariusz Rumiński 1 год назад
Родитель
Сommit
d408658c8b

+ 0 - 30
dev-tools/phpstan/baseline.php

@@ -221,11 +221,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/Import/GlobalNamespaceImportFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/Import/GroupImportFixer.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Method PhpCsFixer\\\\Fixer\\\\Import\\\\OrderedImportsFixer\\:\\:getNewOrder\\(\\) return type has no value type specified in iterable type array\\.$#',
 	'count' => 1,
@@ -281,11 +276,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/ListNotation/ListSyntaxFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Fixer/Operator/ConcatSpaceFixer.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Variable method call on \\$this\\(PhpCsFixer\\\\Fixer\\\\Operator\\\\ConcatSpaceFixer\\)\\.$#',
 	'count' => 1,
@@ -401,16 +391,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Fixer/Whitespace/StatementIndentationFixer.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Linter/ProcessLintingResult.php',
-];
-$ignoreErrors[] = [
-	'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../src/Runner/Runner.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Parameter \\#1 \\$className \\(string\\) of method PhpCsFixer\\\\StdinFileInfo\\:\\:getFileInfo\\(\\) should be contravariant with parameter \\$class \\(string\\|null\\) of method SplFileInfo\\:\\:getFileInfo\\(\\)$#',
 	'count' => 1,
@@ -421,11 +401,6 @@ $ignoreErrors[] = [
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/StdinFileInfo.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
-	'count' => 2,
-	'path' => __DIR__ . '/../../src/Tokenizer/Analyzer/Analysis/ArgumentAnalysis.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Foreach overwrites \\$key with its key variable\\.$#',
 	'count' => 1,
@@ -466,11 +441,6 @@ $ignoreErrors[] = [
 	'count' => 5,
 	'path' => __DIR__ . '/../../src/Tokenizer/Tokens.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Variable \\$expression might not be defined\\.$#',
-	'count' => 1,
-	'path' => __DIR__ . '/../../tests/DocBlock/TypeExpressionTest.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Parameter \\#1 \\$index \\(int\\) of method PhpCsFixer\\\\Tests\\\\Test\\\\TokensWithObservedTransformers\\:\\:offsetSet\\(\\) should be contravariant with parameter \\$offset \\(int\\|null\\) of method ArrayAccess\\<int,PhpCsFixer\\\\Tokenizer\\\\Token\\|null\\>\\:\\:offsetSet\\(\\)$#',
 	'count' => 1,

+ 3 - 1
src/Fixer/Import/GroupImportFixer.php

@@ -89,7 +89,9 @@ final class GroupImportFixer extends AbstractFixer
             $namespaceA = $this->getNamespaceNameWithSlash($a);
             $namespaceB = $this->getNamespaceNameWithSlash($b);
 
-            return \strlen($namespaceA) - \strlen($namespaceB) ?: strcmp($a->getFullName(), $b->getFullName());
+            $namespaceDifference = \strlen($namespaceA) - \strlen($namespaceB);
+
+            return 0 !== $namespaceDifference ? $namespaceDifference : strcmp($a->getFullName(), $b->getFullName());
         });
 
         return $sameNamespaceAnalysis;

+ 8 - 1
src/Fixer/Operator/ConcatSpaceFixer.php

@@ -132,10 +132,17 @@ final class ConcatSpaceFixer extends AbstractFixer implements ConfigurableFixerI
      */
     private function fixWhiteSpaceAroundConcatToken(Tokens $tokens, int $index, int $offset): void
     {
+        if (-1 !== $offset && 1 !== $offset) {
+            throw new \InvalidArgumentException(sprintf(
+                'Expected `-1|1` for "$offset", got "%s"',
+                $offset
+            ));
+        }
+
         $offsetIndex = $index + $offset;
 
         if (!$tokens[$offsetIndex]->isWhitespace()) {
-            $tokens->insertAt($index + (1 === $offset ?: 0), new Token([T_WHITESPACE, ' ']));
+            $tokens->insertAt($index + (1 === $offset ? 1 : 0), new Token([T_WHITESPACE, ' ']));
 
             return;
         }

+ 2 - 1
src/Linter/ProcessLintingResult.php

@@ -45,7 +45,8 @@ final class ProcessLintingResult implements LintingResultInterface
 
     private function getProcessErrorMessage(): string
     {
-        $output = strtok(ltrim($this->process->getErrorOutput() ?: $this->process->getOutput()), "\n");
+        $errorOutput = $this->process->getErrorOutput();
+        $output = strtok(ltrim('' !== $errorOutput ? $errorOutput : $this->process->getOutput()), "\n");
 
         if (false === $output) {
             return 'Fatal error: Unable to lint file.';

+ 1 - 1
src/Runner/Runner.php

@@ -87,7 +87,7 @@ final class Runner
         $this->linter = $linter;
         $this->isDryRun = $isDryRun;
         $this->cacheManager = $cacheManager;
-        $this->directory = $directory ?: new Directory('');
+        $this->directory = $directory ?? new Directory('');
         $this->stopOnViolation = $stopOnViolation;
     }
 

+ 2 - 2
src/Tokenizer/Analyzer/Analysis/ArgumentAnalysis.php

@@ -43,8 +43,8 @@ final class ArgumentAnalysis
     {
         $this->name = $name;
         $this->nameIndex = $nameIndex;
-        $this->default = $default ?: null;
-        $this->typeAnalysis = $typeAnalysis ?: null;
+        $this->default = $default ?? null;
+        $this->typeAnalysis = $typeAnalysis ?? null;
     }
 
     public function getDefault(): ?string

+ 1 - 0
tests/DocBlock/TypeExpressionTest.php

@@ -864,6 +864,7 @@ final class TypeExpressionTest extends TestCase
     {
         $pcreJitBackup = \ini_get('pcre.jit');
 
+        $expression = null;
         $innerExpressionsDataWithoutJit = null;
 
         try {