Skip to content

Commit 1408b3b

Browse files
author
matt
committed
Psalm fixes
1 parent 5026edb commit 1408b3b

17 files changed

+99
-61
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor/
22
/.phpcs-cache
33
/.phpunit.result.cache
4+
/.phpunit.cache/

phpunit.xml.dist

+21-30
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
beStrictAboutCoversAnnotation="true"
6-
beStrictAboutOutputDuringTests="true"
7-
beStrictAboutTodoAnnotatedTests="true"
8-
bootstrap="vendor/autoload.php"
9-
convertDeprecationsToExceptions="true"
10-
executionOrder="depends,defects"
11-
failOnRisky="true"
12-
failOnWarning="true"
13-
verbose="true"
14-
colors="true">
15-
<testsuites>
16-
<testsuite name="default">
17-
<directory >test</directory>
18-
</testsuite>
19-
</testsuites>
20-
21-
<coverage processUncoveredFiles="true">
22-
<include>
23-
<directory suffix=".php">src</directory>
24-
</include>
25-
</coverage>
26-
27-
<php>
28-
<!-- Seems to be needed by CI's PHP8.2-RC1? Not needed in PHP8.2-dev locally! -->
29-
<ini name="assert.exception" value="1" />
30-
<ini name="assert.warning" value="0" />
31-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
beStrictAboutOutputDuringTests="true"
5+
bootstrap="vendor/autoload.php"
6+
executionOrder="depends,defects"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
colors="true"
10+
cacheDirectory=".phpunit.cache"
11+
beStrictAboutCoverageMetadata="true"
12+
>
13+
<testsuites>
14+
<testsuite name="default">
15+
<directory>test</directory>
16+
</testsuite>
17+
</testsuites>
18+
<source>
19+
<include>
20+
<directory suffix=".php">src</directory>
21+
</include>
22+
</source>
3223
</phpunit>

psalm.xml

+8-10
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
findUnusedBaselineEntry="true"
9+
findUnusedCode="true"
810
>
911
<projectFiles>
10-
<directory name="src" />
11-
<directory name="test" />
12+
<directory name="src"/>
13+
<directory name="test"/>
1214
<ignoreFiles>
13-
<directory name="vendor" />
15+
<directory name="vendor"/>
1416
</ignoreFiles>
1517
</projectFiles>
1618

17-
<issueHandlers>
18-
<PropertyNotSetInConstructor>
19-
<errorLevel type="suppress">
20-
<directory name="test"/>
21-
</errorLevel>
22-
</PropertyNotSetInConstructor>
23-
</issueHandlers>
19+
<plugins>
20+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
21+
</plugins>
2422
</psalm>

src/AbstractNormalizer.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ abstract class AbstractNormalizer implements NormalizerInterface
3737
/**
3838
* @see https://www.php.net/manual/en/reserved.keywords.php
3939
* @see https://www.php.net/manual/en/reserved.other-reserved-words.php
40+
*
41+
* @var list<string>
4042
*/
4143
protected const RESERVED = [
4244
'abstract',
@@ -318,7 +320,7 @@ private function spellOutNonAscii(string $string): string
318320

319321
private function spellOutNonAsciiChar(int $ord): string
320322
{
321-
$speltOut = IntlChar::charName($ord);
323+
$speltOut = (string) IntlChar::charName($ord);
322324

323325
// 'EURO SIGN' -> 'euro'
324326
return implode(' ', array_map(function (string $part): string {

src/ClassConstantNameNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final class ClassConstantNameNormalizer extends AbstractNormalizer
1111
{
1212
protected const RESERVED = [
13-
'class'
13+
'class',
1414
];
1515

1616
public function __construct(

src/NormalizerException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static function transliterationFailure(string $string, string|false $erro
1818
return new self(sprintf(
1919
"Cannot transliterate '%s': %s",
2020
$string,
21-
$error ?: "Unknown error"
21+
$error !== false ? $error : "Unknown error"
2222
));
2323
}
2424

test/AbstractNormalizerTest.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public function testNormalize(string $label, string $expected): void
3333
self::assertSame($expected, $actual);
3434
}
3535

36-
public function labelProvider(): array
36+
/**
37+
* @return array<string, list{string, string}>
38+
*/
39+
public static function labelProvider(): array
3740
{
3841
return [
3942
'pet_shop' => ['ペット ショップ', 'PettoShoppu'],
@@ -65,7 +68,10 @@ public function testNormalizeUsesCase(WordCase $case, string $expected): void
6568
self::assertSame($expected, $actual);
6669
}
6770

68-
public function caseProvider(): array
71+
/**
72+
* @return array<string, list{WordCase, string}>
73+
*/
74+
public static function caseProvider(): array
6975
{
7076
return [
7177
'camelCase' => [WordCase::Camel, 'fooBar'],
@@ -84,7 +90,10 @@ public function testSpellOutCase(WordCase $case, string $label, string $expected
8490
self::assertSame($expected, $actual);
8591
}
8692

87-
public function spellOutCaseProvider(): array
93+
/**
94+
* @return array<string, list{WordCase, string, string}>
95+
*/
96+
public static function spellOutCaseProvider(): array
8897
{
8998
return [
9099
'nonascii-before-camelCase' => [WordCase::Camel, '😫foo', 'tiredFaceFoo'],
@@ -156,7 +165,10 @@ public function testPrepareSuffixInvalidThrowsException(string $suffix): void
156165
);
157166
}
158167

159-
public function invalidSuffixProvider(): array
168+
/**
169+
* @return array<string, list{string}>
170+
*/
171+
public static function invalidSuffixProvider(): array
160172
{
161173
return [
162174
'empty' => [''],

test/AbstractUniqueLabelerTest.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@ final class AbstractUniqueLabelerTest extends TestCase
2626
*/
2727
public function testGetUnique(array $labels, bool $caseSensitive, array $expected): void
2828
{
29-
$namer = self::getMockForAbstractClass(AbstractUniqueLabeler::class, [
29+
$namer = new class (
3030
new PropertyNameNormalizer(),
3131
new NumberSuffix(),
32-
$caseSensitive,
33-
]);
32+
$caseSensitive
33+
) extends AbstractUniqueLabeler {
34+
};
3435
$actual = $namer->getUnique($labels);
3536
self::assertSame($expected, $actual);
3637
}
3738

38-
public function labelProvider(): array
39+
/**
40+
* @return array<string, list{list<string>, bool, array<string, string>}>
41+
*/
42+
public static function labelProvider(): array
3943
{
4044
return [
4145
'all_unique' => [['a', 'b', 'c'], true, ['a' => 'a', 'b' => 'b', 'c' => 'c']],

test/ClassConstantNameNormalizerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public function testNormalize(string $constantName, WordCase $case, string $expe
2323
self::assertSame($expected, $actual);
2424
}
2525

26-
public function constantNameProvider(): array
26+
/**
27+
* @return array<string, list{string, WordCase, string}>
28+
*/
29+
public static function constantNameProvider(): array
2730
{
2831
return [
2932
'unicode_spellout' => ['€ sign', WordCase::UpperSnake, 'EURO_SIGN'],

test/ClassNameNormalizerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public function testNormalize(string $className, WordCase $case, string $expecte
2727
self::assertSame($expected, $actual);
2828
}
2929

30-
public function classNameProvider(): array
30+
/**
31+
* @return array<string, list{string, WordCase, string}>
32+
*/
33+
public static function classNameProvider(): array
3134
{
3235
return [
3336
'unicode_spellout' => ['', WordCase::Pascal, 'Euro'],

test/ConstantNameNormalizerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public function testNormalize(string $constantName, WordCase $case, string $expe
2727
self::assertSame($expected, $actual);
2828
}
2929

30-
public function constantNameProvider(): array
30+
/**
31+
* @return array<string, list{string, WordCase, string}>
32+
*/
33+
public static function constantNameProvider(): array
3134
{
3235
return [
3336
'unicode_spellout' => ['€ sign', WordCase::UpperSnake, 'EURO_SIGN'],

test/PhpLabelTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public function testIsValid(PhpLabel $label, string $string, bool $expected): vo
2121
self::assertSame($expected, $actual);
2222
}
2323

24-
public function isValidProvider(): array
24+
/**
25+
* @return array<string, list{PhpLabel, string, bool}>
26+
*/
27+
public static function isValidProvider(): array
2528
{
2629
return [
2730
'label_empty' => [PhpLabel::Label, '', false],

test/PropertyNameNormalizerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public function testNormalizePropertyName(string $propertyName, WordCase $case,
2727
self::assertSame($expected, $actual);
2828
}
2929

30-
public function propertyNameProvider(): array
30+
/**
31+
* @return array<string, list{string, WordCase, string}>
32+
*/
33+
public static function propertyNameProvider(): array
3134
{
3235
return [
3336
'unicode_spellout' => ['', WordCase::Camel, 'euro'],

test/UniqueStrategy/NumberSuffixTest.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function testGenerateUniqueName(WordCase $case, string $label, int $occur
2525
self::assertSame($expected, $actual);
2626
}
2727

28-
public function labelProvider(): array
28+
/**
29+
* @return array<string, list{WordCase, string, int, string}>
30+
*/
31+
public static function labelProvider(): array
2932
{
3033
return [
3134
'first_snake' => [WordCase::LowerSnake, 'foo', 1, 'foo_1'],
@@ -44,7 +47,10 @@ public function testGenerateUniqueNameUsesSuffix(WordCase $case, string $label,
4447
self::assertSame($expected, $actual);
4548
}
4649

47-
public function suffixLabelProvider(): array
50+
/**
51+
* @return array<string, list{WordCase, string, string}>
52+
*/
53+
public static function suffixLabelProvider(): array
4854
{
4955
return [
5056
'camelCase' => [WordCase::Camel, 'fooBar', 'fooBarVersion2'],

test/UniqueStrategy/SpellOutOrdinalPrefixTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function testGenerateUniqueName(WordCase $case, string $label, int $occur
2525
self::assertSame($expected, $actual);
2626
}
2727

28-
public function labelProvider(): array
28+
/**
29+
* @return array<string, list{WordCase, string, int, string}>
30+
*/
31+
public static function labelProvider(): array
2932
{
3033
return [
3134
'first_snake' => [WordCase::LowerSnake, 'snake', 1, 'first_snake'],

test/VariableNameNormalizerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public function testNormalizeVariableName(
3131
self::assertSame($expected, $actual);
3232
}
3333

34-
public function variableNameProvider(): array
34+
/**
35+
* @return array<string, list{string, string, WordCase, string}>
36+
*/
37+
public static function variableNameProvider(): array
3538
{
3639
return [
3740
'unicode_spellout' => ['', 'me', WordCase::Camel, '$euro'],

test/WordCaseTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public function testConvert(WordCase $case, string $string, string $expected): v
2121
self::assertSame($expected, $actual);
2222
}
2323

24-
public function stringProvider(): array
24+
/**
25+
* @return array<string, list{WordCase, string, string}>
26+
*/
27+
public static function stringProvider(): array
2528
{
2629
return [
2730
'empty' => [WordCase::LowerSnake, '', ''],

0 commit comments

Comments
 (0)