Skip to content

Commit 879be48

Browse files
authored
Revert PHP 7.2 support and require at least 8.1 (#14)
* Revert "Widen PHP support (#10)" This reverts commit 7532a89. * Lower PHP requirement to 8.1 PHPStan 2.0 is in the works, and it will only support 8.1 and higher. * Run PHPStan on 8.1 (lowest) * Move readonly to class properties
1 parent 10f85b3 commit 879be48

File tree

5 files changed

+37
-71
lines changed

5 files changed

+37
-71
lines changed

.github/workflows/ci.yaml

+1-9
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ concurrency:
1010

1111
jobs:
1212
phpstan:
13-
strategy:
14-
fail-fast: false
15-
matrix:
16-
php:
17-
- '7.2'
18-
- '8.3'
19-
- '8.4'
20-
2113
runs-on: ubuntu-latest
2214

2315
steps:
@@ -27,7 +19,7 @@ jobs:
2719
- name: Set up PHP
2820
uses: shivammathur/setup-php@v2
2921
with:
30-
php-version: ${{ matrix.php }}
22+
php-version: '8.1'
3123

3224
- name: Install Composer packages
3325
uses: ramsey/composer-install@v3

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"keywords": ["phpstan", "dev"],
55
"type": "phpstan-extension",
66
"require": {
7-
"php": "^7.2|^8.0",
7+
"php": "^8.1",
88
"phpstan/phpstan": "^1.12.4"
99
},
1010
"license": "MIT",

composer.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ parameters:
44
level: 8
55
paths:
66
- src
7-
phpVersion: 70200
7+
phpVersion: 80100
88
errorFormat: ticketswap
99
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'

src/TicketSwapErrorFormatter.php

+32-58
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,24 @@ final class TicketSwapErrorFormatter implements ErrorFormatter
1919
private const LINK_FORMAT_PHPSTORM = "↳ file://{absolutePath}:{line}\n";
2020
private const LINK_FORMAT_WITHOUT_EDITOR = "↳ {relativePath}:{line}\n";
2121

22-
/**
23-
* @var string
24-
*/
25-
private $linkFormat;
26-
27-
/**
28-
* @var RelativePathHelper
29-
*/
30-
private $relativePathHelper;
31-
32-
/**
33-
* @var CiDetectedErrorFormatter
34-
*/
35-
private $ciDetectedErrorFormatter;
36-
37-
/**
38-
* @var string|null
39-
*/
40-
private $editorUrl;
22+
private string $linkFormat;
4123

4224
public function __construct(
43-
RelativePathHelper $relativePathHelper,
44-
CiDetectedErrorFormatter $ciDetectedErrorFormatter,
45-
?string $editorUrl = null
25+
private readonly RelativePathHelper $relativePathHelper,
26+
private readonly CiDetectedErrorFormatter $ciDetectedErrorFormatter,
27+
private readonly ?string $editorUrl,
4628
) {
47-
$this->editorUrl = $editorUrl;
48-
$this->ciDetectedErrorFormatter = $ciDetectedErrorFormatter;
49-
$this->relativePathHelper = $relativePathHelper;
5029
$this->linkFormat = self::getLinkFormatFromEnv();
5130
}
5231

5332
public static function getLinkFormatFromEnv() : string
5433
{
55-
if (getenv('GITHUB_ACTIONS') !== false) {
56-
return self::LINK_FORMAT_GITHUB_ACTIONS;
57-
}
58-
if (getenv('TERMINAL_EMULATOR') !== 'JetBrains-JediTerm') {
59-
return self::LINK_FORMAT_PHPSTORM;
60-
}
61-
if (getenv('TERM_PROGRAM') !== 'WarpTerminal') {
62-
return self::LINK_FORMAT_WARP;
63-
}
64-
65-
return self::LINK_FORMAT_DEFAULT;
34+
return match (true) {
35+
getenv('GITHUB_ACTIONS') !== false => self::LINK_FORMAT_GITHUB_ACTIONS,
36+
getenv('TERMINAL_EMULATOR') === 'JetBrains-JediTerm' => self::LINK_FORMAT_PHPSTORM,
37+
getenv('TERM_PROGRAM') === 'WarpTerminal' => self::LINK_FORMAT_WARP,
38+
default => self::LINK_FORMAT_DEFAULT,
39+
};
6640
}
6741

6842
public function formatErrors(AnalysisResult $analysisResult, Output $output) : int
@@ -78,7 +52,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
7852
$output->writeLineFormatted(
7953
sprintf(
8054
'<unknown location> %s',
81-
$notFileSpecificError
55+
$notFileSpecificError,
8256
)
8357
);
8458
}
@@ -101,7 +75,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
10175
$error->getTip()
10276
) : null,
10377
$error->getIdentifier(),
104-
$output->isDecorated()
78+
$output->isDecorated(),
10579
),
10680
'{identifier}' => $error->getIdentifier(),
10781
'{links}' => implode([
@@ -111,19 +85,19 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
11185
$error->getFilePath(),
11286
$this->relativePathHelper->getRelativePath($error->getFilePath()),
11387
$this->editorUrl,
114-
$output->isDecorated()
88+
$output->isDecorated(),
11589
),
11690
$error->getTraitFilePath() !== null ? $this::link(
11791
$this->linkFormat,
11892
(int) $error->getLine(),
11993
$error->getTraitFilePath(),
12094
$this->relativePathHelper->getRelativePath($error->getTraitFilePath()),
12195
$this->editorUrl,
122-
$output->isDecorated()
96+
$output->isDecorated(),
12397
) : '',
12498
]),
125-
]
126-
)
99+
],
100+
),
127101
);
128102
}
129103

@@ -136,7 +110,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
136110
sprintf(
137111
'<bg=red;options=bold>Found %d error%s</>',
138112
$analysisResult->getTotalErrorsCount(),
139-
$analysisResult->getTotalErrorsCount() === 1 ? '' : 's'
113+
$analysisResult->getTotalErrorsCount() === 1 ? '' : 's',
140114
)
141115
);
142116
$output->writeLineFormatted('');
@@ -152,7 +126,7 @@ public static function link(
152126
string $absolutePath,
153127
string $relativePath,
154128
?string $editorUrl,
155-
bool $isDecorated
129+
bool $isDecorated,
156130
) : string {
157131
if (!$isDecorated || $editorUrl === null) {
158132
$format = self::LINK_FORMAT_WITHOUT_EDITOR;
@@ -165,12 +139,12 @@ public static function link(
165139
'{editorUrl}' => $editorUrl === null ? '' : str_replace(
166140
['%relFile%', '%file%', '%line%'],
167141
[$relativePath, $absolutePath, $line],
168-
$editorUrl
142+
$editorUrl,
169143
),
170144
'{relativePath}' => $relativePath,
171145
'{shortPath}' => self::trimPath($relativePath),
172146
'{line}' => $line,
173-
]
147+
],
174148
);
175149
}
176150

@@ -183,11 +157,11 @@ private static function trimPath(string $path) : string
183157

184158
return implode(
185159
DIRECTORY_SEPARATOR,
186-
array_merge(
187-
array_slice($parts, 0, 3),
188-
['...'],
189-
array_slice($parts, -2)
190-
)
160+
[
161+
...array_slice($parts, 0, 3),
162+
'...',
163+
...array_slice($parts, -2),
164+
],
191165
);
192166
}
193167

@@ -197,7 +171,7 @@ public static function highlight(string $message, ?string $tip, ?string $identif
197171
return $message;
198172
}
199173

200-
if (strpos($message, 'Ignored error pattern') === 0) {
174+
if (str_starts_with($message, 'Ignored error pattern')) {
201175
return $message;
202176
}
203177

@@ -208,42 +182,42 @@ public static function highlight(string $message, ?string $tip, ?string $identif
208182
$message = (string) preg_replace(
209183
"/([A-Z0-9]{1}[A-Za-z0-9_\-]+[\\\]+[A-Z0-9]{1}[A-Za-z0-9_\-\\\]+)/",
210184
'<fg=yellow>$1</>',
211-
$message
185+
$message,
212186
);
213187

214188
// Quoted strings
215189
$message = (string) preg_replace(
216190
"/(?<=[\"'])([A-Za-z0-9_\-\\\]+)(?=[\"'])/",
217191
'<fg=yellow>$1</>',
218-
$message
192+
$message,
219193
);
220194

221195
// Variable
222196
$message = (string) preg_replace(
223197
"/(?<=[:]{2}|[\s\"\(])([.]{3})?(\\$[A-Za-z0-9_\\-]+)(?=[\s|\"|\)]|$)/",
224198
'<fg=green>$1$2</>',
225-
$message
199+
$message,
226200
);
227201

228202
// Method
229203
$message = (string) preg_replace(
230204
'/(?<=[:]{2}|[\s])(\w+\(\))/',
231205
'<fg=blue>$1</>',
232-
$message
206+
$message,
233207
);
234208

235209
// Function
236210
$message = (string) preg_replace(
237211
'/(?<=function\s)(\w+)(?=\s)/',
238212
'<fg=blue>$1</>',
239-
$message
213+
$message,
240214
);
241215

242216
// Types
243217
$message = (string) preg_replace(
244218
'/(?<=[\s\|\(><])(null|true|false|int|float|bool|([-\w]+-)?string|array|object|mixed|resource|iterable|void|callable)(?=[:]{2}|[\.\s\|><,\(\)\{\}]+)/',
245219
'<fg=magenta>$1</>',
246-
$message
220+
$message,
247221
);
248222

249223
if ($tip !== null) {

0 commit comments

Comments
 (0)