diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 903d139..d7425ee 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,14 +10,6 @@ concurrency: jobs: phpstan: - strategy: - fail-fast: false - matrix: - php: - - '7.2' - - '8.3' - - '8.4' - runs-on: ubuntu-latest steps: @@ -27,7 +19,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} + php-version: '8.1' - name: Install Composer packages uses: ramsey/composer-install@v3 diff --git a/composer.json b/composer.json index 4ac2d2a..6f943bf 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "keywords": ["phpstan", "dev"], "type": "phpstan-extension", "require": { - "php": "^7.2|^8.0", + "php": "^8.1", "phpstan/phpstan": "^1.12.4" }, "license": "MIT", diff --git a/composer.lock b/composer.lock index b263f92..0591986 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "456d341fe88e737f478ae46cadcb1e3a", + "content-hash": "5f2f2552b7da7e6411234694404e9345", "packages": [ { "name": "phpstan/phpstan", @@ -72,7 +72,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^8.2" + "php": "^8.1" }, "platform-dev": [], "plugin-api-version": "2.6.0" diff --git a/phpstan.neon b/phpstan.neon index da46f2e..8b3405e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,6 +4,6 @@ parameters: level: 8 paths: - src - phpVersion: 70200 + phpVersion: 80100 errorFormat: ticketswap editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%' diff --git a/src/TicketSwapErrorFormatter.php b/src/TicketSwapErrorFormatter.php index dc5bd5d..445e7fd 100644 --- a/src/TicketSwapErrorFormatter.php +++ b/src/TicketSwapErrorFormatter.php @@ -19,50 +19,24 @@ final class TicketSwapErrorFormatter implements ErrorFormatter private const LINK_FORMAT_PHPSTORM = "↳ file://{absolutePath}:{line}\n"; private const LINK_FORMAT_WITHOUT_EDITOR = "↳ {relativePath}:{line}\n"; - /** - * @var string - */ - private $linkFormat; - - /** - * @var RelativePathHelper - */ - private $relativePathHelper; - - /** - * @var CiDetectedErrorFormatter - */ - private $ciDetectedErrorFormatter; - - /** - * @var string|null - */ - private $editorUrl; + private string $linkFormat; public function __construct( - RelativePathHelper $relativePathHelper, - CiDetectedErrorFormatter $ciDetectedErrorFormatter, - ?string $editorUrl = null + private readonly RelativePathHelper $relativePathHelper, + private readonly CiDetectedErrorFormatter $ciDetectedErrorFormatter, + private readonly ?string $editorUrl, ) { - $this->editorUrl = $editorUrl; - $this->ciDetectedErrorFormatter = $ciDetectedErrorFormatter; - $this->relativePathHelper = $relativePathHelper; $this->linkFormat = self::getLinkFormatFromEnv(); } public static function getLinkFormatFromEnv() : string { - if (getenv('GITHUB_ACTIONS') !== false) { - return self::LINK_FORMAT_GITHUB_ACTIONS; - } - if (getenv('TERMINAL_EMULATOR') !== 'JetBrains-JediTerm') { - return self::LINK_FORMAT_PHPSTORM; - } - if (getenv('TERM_PROGRAM') !== 'WarpTerminal') { - return self::LINK_FORMAT_WARP; - } - - return self::LINK_FORMAT_DEFAULT; + return match (true) { + getenv('GITHUB_ACTIONS') !== false => self::LINK_FORMAT_GITHUB_ACTIONS, + getenv('TERMINAL_EMULATOR') === 'JetBrains-JediTerm' => self::LINK_FORMAT_PHPSTORM, + getenv('TERM_PROGRAM') === 'WarpTerminal' => self::LINK_FORMAT_WARP, + default => self::LINK_FORMAT_DEFAULT, + }; } public function formatErrors(AnalysisResult $analysisResult, Output $output) : int @@ -78,7 +52,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i $output->writeLineFormatted( sprintf( ' %s', - $notFileSpecificError + $notFileSpecificError, ) ); } @@ -101,7 +75,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i $error->getTip() ) : null, $error->getIdentifier(), - $output->isDecorated() + $output->isDecorated(), ), '{identifier}' => $error->getIdentifier(), '{links}' => implode([ @@ -111,7 +85,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i $error->getFilePath(), $this->relativePathHelper->getRelativePath($error->getFilePath()), $this->editorUrl, - $output->isDecorated() + $output->isDecorated(), ), $error->getTraitFilePath() !== null ? $this::link( $this->linkFormat, @@ -119,11 +93,11 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i $error->getTraitFilePath(), $this->relativePathHelper->getRelativePath($error->getTraitFilePath()), $this->editorUrl, - $output->isDecorated() + $output->isDecorated(), ) : '', ]), - ] - ) + ], + ), ); } @@ -136,7 +110,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i sprintf( 'Found %d error%s', $analysisResult->getTotalErrorsCount(), - $analysisResult->getTotalErrorsCount() === 1 ? '' : 's' + $analysisResult->getTotalErrorsCount() === 1 ? '' : 's', ) ); $output->writeLineFormatted(''); @@ -152,7 +126,7 @@ public static function link( string $absolutePath, string $relativePath, ?string $editorUrl, - bool $isDecorated + bool $isDecorated, ) : string { if (!$isDecorated || $editorUrl === null) { $format = self::LINK_FORMAT_WITHOUT_EDITOR; @@ -165,12 +139,12 @@ public static function link( '{editorUrl}' => $editorUrl === null ? '' : str_replace( ['%relFile%', '%file%', '%line%'], [$relativePath, $absolutePath, $line], - $editorUrl + $editorUrl, ), '{relativePath}' => $relativePath, '{shortPath}' => self::trimPath($relativePath), '{line}' => $line, - ] + ], ); } @@ -183,11 +157,11 @@ private static function trimPath(string $path) : string return implode( DIRECTORY_SEPARATOR, - array_merge( - array_slice($parts, 0, 3), - ['...'], - array_slice($parts, -2) - ) + [ + ...array_slice($parts, 0, 3), + '...', + ...array_slice($parts, -2), + ], ); } @@ -197,7 +171,7 @@ public static function highlight(string $message, ?string $tip, ?string $identif return $message; } - if (strpos($message, 'Ignored error pattern') === 0) { + if (str_starts_with($message, 'Ignored error pattern')) { return $message; } @@ -208,42 +182,42 @@ public static function highlight(string $message, ?string $tip, ?string $identif $message = (string) preg_replace( "/([A-Z0-9]{1}[A-Za-z0-9_\-]+[\\\]+[A-Z0-9]{1}[A-Za-z0-9_\-\\\]+)/", '$1', - $message + $message, ); // Quoted strings $message = (string) preg_replace( "/(?<=[\"'])([A-Za-z0-9_\-\\\]+)(?=[\"'])/", '$1', - $message + $message, ); // Variable $message = (string) preg_replace( "/(?<=[:]{2}|[\s\"\(])([.]{3})?(\\$[A-Za-z0-9_\\-]+)(?=[\s|\"|\)]|$)/", '$1$2', - $message + $message, ); // Method $message = (string) preg_replace( '/(?<=[:]{2}|[\s])(\w+\(\))/', '$1', - $message + $message, ); // Function $message = (string) preg_replace( '/(?<=function\s)(\w+)(?=\s)/', '$1', - $message + $message, ); // Types $message = (string) preg_replace( '/(?<=[\s\|\(><])(null|true|false|int|float|bool|([-\w]+-)?string|array|object|mixed|resource|iterable|void|callable)(?=[:]{2}|[\.\s\|><,\(\)\{\}]+)/', '$1', - $message + $message, ); if ($tip !== null) {