Skip to content

Commit dae0125

Browse files
committed
Switch from Psalm to PHPStan
1 parent d913756 commit dae0125

File tree

14 files changed

+36
-96
lines changed

14 files changed

+36
-96
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name: CI
33
on: [push, pull_request]
44

55
env:
6-
PSALM_PHP_VERSION: "8.5"
6+
PHPSTAN_PHP_VERSION: "8.5"
77
COVERAGE_PHP_VERSION: "8.5"
88

99
jobs:
10-
psalm:
11-
name: Psalm
10+
phpstan:
11+
name: PHPStan
1212
runs-on: ubuntu-latest
1313

1414
steps:
@@ -18,13 +18,13 @@ jobs:
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: ${{ env.PSALM_PHP_VERSION }}
21+
php-version: ${{ env.PHPSTAN_PHP_VERSION }}
2222

2323
- name: Install composer dependencies
2424
uses: ramsey/composer-install@v3
2525

26-
- name: Run Psalm
27-
run: vendor/bin/psalm --show-info=false --find-unused-psalm-suppress --no-progress
26+
- name: Run PHPStan
27+
run: vendor/bin/phpstan --no-progress
2828

2929
coding-standard:
3030
name: Coding Standard

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"require-dev": {
1717
"phpunit/phpunit": "^11.0",
18-
"vimeo/psalm": "6.14.3"
18+
"phpstan/phpstan": "2.1.42"
1919
},
2020
"autoload": {
2121
"psr-4": {

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 10
3+
checkUninitializedProperties: true
4+
ignoreErrors:
5+
- identifier: missingType.iterableValue
6+
paths:
7+
- src

psalm-baseline.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.

psalm.xml

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/JsonMapper.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030

3131
use const JSON_THROW_ON_ERROR;
3232

33-
/**
34-
* @psalm-suppress MixedAssignment
35-
*/
3633
final readonly class JsonMapper
3734
{
3835
private Reflector $reflector;
@@ -126,7 +123,7 @@ private function mapToObject(stdClass $jsonData, string $className): object
126123
{
127124
try {
128125
$reflectionClass = new ReflectionClass($className);
129-
} catch (ReflectionException $e) {
126+
} catch (ReflectionException $e) { // @phpstan-ignore catch.neverThrown
130127
throw new JsonMapperException('Invalid class name: ' . $className, $e);
131128
}
132129

@@ -152,9 +149,8 @@ private function mapToObject(stdClass $jsonData, string $className): object
152149
}
153150

154151
if ($this->onExtraProperties === OnExtraProperties::ThrowException) {
155-
/** @psalm-suppress MixedAssignment, RawObjectIteration */
156-
foreach ($jsonData as $jsonPropertyName => $_) {
157-
/** @var string $jsonPropertyName https://github.com/vimeo/psalm/issues/9108 */
152+
foreach ($jsonData as $jsonPropertyName => $_) { // @phpstan-ignore foreach.nonIterable
153+
/** @var string $jsonPropertyName */
158154
if (! in_array($jsonPropertyName, $consumedJsonPropertyNames, true)) {
159155
throw new JsonMapperException([
160156
sprintf(

src/NameMapper/CamelCaseToSnakeCaseMapper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ final class CamelCaseToSnakeCaseMapper implements NameMapper
1515
#[Override]
1616
public function mapName(string $name): string
1717
{
18-
return preg_replace_callback(
18+
$result = preg_replace_callback(
1919
'/[A-Z]/',
2020
fn (array $matches) => '_' . strtolower($matches[0]),
2121
$name,
2222
);
23+
24+
assert($result !== null);
25+
26+
return $result;
2327
}
2428
}

src/NameMapper/SnakeCaseToCamelCaseMapper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ final class SnakeCaseToCamelCaseMapper implements NameMapper
1515
#[Override]
1616
public function mapName(string $name): string
1717
{
18-
return preg_replace_callback(
18+
$result = preg_replace_callback(
1919
'/_([a-z])/',
2020
fn (array $matches) => strtoupper($matches[1]),
2121
$name,
2222
);
23+
24+
assert($result !== null);
25+
26+
return $result;
2327
}
2428
}

src/Reflection/Reflector.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ private function getParameterTypeFromDocComment(ReflectionParameter $parameter):
162162

163163
$pattern = '/@param(.*)\$' . $parameter->getName() . '\W/';
164164

165-
/** @var list<array{string}> $matches */
166165
preg_match_all($pattern, $docComment, $matches, PREG_SET_ORDER);
167166

168167
if (count($matches) === 0) {
@@ -186,6 +185,7 @@ private function getParameterTypeFromDocComment(ReflectionParameter $parameter):
186185
}
187186

188187
$type = preg_replace('/(^\s+)|(\s+$)/', '', $type);
188+
assert($type !== null);
189189

190190
if ($type === '') {
191191
throw new JsonMapperException(sprintf(
@@ -208,6 +208,7 @@ private function getParameterTypeFromDocComment(ReflectionParameter $parameter):
208208

209209
return $this->createUnionType(
210210
array_map(
211+
// @phpstan-ignore argument.type
211212
fn (string|array $value) => $this->convertDocCommentType($value, $parameter),
212213
$parsedType,
213214
),
@@ -232,6 +233,7 @@ private function convertDocCommentType(string|array $type, ReflectionParameter $
232233
return new ArrayType(
233234
$this->createUnionType(
234235
array_map(
236+
// @phpstan-ignore argument.type
235237
fn (string|array $type) => $this->convertDocCommentType($type, $reflectionParameter),
236238
$type,
237239
),
@@ -252,7 +254,7 @@ private function getParameterTypeFromReflection(ReflectionType $type, Reflection
252254
if ($type instanceof ReflectionUnionType) {
253255
return $this->createUnionType(
254256
array_map(
255-
function (ReflectionNamedType|ReflectionIntersectionType $type) use ($reflectionParameter): SimpleType|ClassType|EnumType|ArrayType {
257+
function (ReflectionNamedType|ReflectionIntersectionType $type) use ($reflectionParameter): SimpleType|ClassType|EnumType {
256258
if ($type instanceof ReflectionIntersectionType) {
257259
$this->throwOnIntersectionType($reflectionParameter);
258260
}
@@ -375,7 +377,7 @@ private function convertNamedType(string $namedType, bool $isReflection, Reflect
375377
);
376378
}
377379

378-
/** @psalm-var class-string $namedType */
380+
/** @var class-string $namedType */
379381
return new Type\ClassType($namedType);
380382
}
381383

src/Reflection/Type/ArrayType.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public function __construct(
1919
) {
2020
}
2121

22-
/**
23-
* @psalm-suppress ImplicitToStringCast
24-
*/
2522
#[Override]
2623
public function __toString(): string
2724
{

0 commit comments

Comments
 (0)