Skip to content

Commit 171db40

Browse files
committed
Fix auditor errors
1 parent c4d0cb8 commit 171db40

11 files changed

Lines changed: 45 additions & 37 deletions

File tree

.github/workflows/audit.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
name: Audit
88
strategy:
99
matrix:
10-
php-version: [ '8.2', '8.3' ]
10+
php-version: [ '8.2', '8.3', '8.4' ]
1111
fail-fast: false
1212
runs-on: ubuntu-latest
1313
steps:
@@ -54,13 +54,13 @@ jobs:
5454
echo "::endgroup::"
5555
5656
- name: Auditor
57-
uses: docker://nbgrp/auditor:0.23.1
57+
uses: docker://nbgrp/auditor:0.29.0
5858

5959
- name: Tests
6060
run: vendor/bin/simple-phpunit
6161

6262
- name: Codecov
63-
uses: codecov/codecov-action@v3
63+
uses: codecov/codecov-action@v5
6464
with:
6565
token: ${{ secrets.CODECOV_TOKEN }}
6666
files: ./clover.xml

grumphp.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ grumphp:
77
enabled: false
88

99
tasks:
10+
composer:
11+
strict: true
12+
1013
composer_normalize:
1114
indent_size: 4
1215
indent_style: 'space'
@@ -32,4 +35,4 @@ grumphp:
3235
no_cache: true
3336
show_info: true
3437

35-
securitychecker_local: ~
38+
securitychecker_composeraudit: ~

phpcs.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<element value="private methods" />
6262
</property>
6363
</properties>
64+
<exclude-pattern>*/tests/*</exclude-pattern>
6465
</rule>
6566
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing" />
6667
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference" />
@@ -185,14 +186,17 @@
185186

186187
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
187188
<properties>
188-
<property name="linesCountBeforeDeclare" value="0" />
189+
<property name="linesCountBeforeDeclare" value="1" />
189190
<property name="linesCountAfterDeclare" value="1" />
190191
<property name="spacesCountAroundEqualsSign" value="0" />
191192
</properties>
192193
</rule>
193194
<rule ref="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax">
194195
<properties>
195-
<property name="traversableTypeHints" value="true" />
196+
<property name="traversableTypeHints" type="array">
197+
<element value="Traversable" />
198+
<element value="\ArrayIterator" />
199+
</property>
196200
</properties>
197201
</rule>
198202
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
@@ -204,9 +208,9 @@
204208
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
205209
</rule>
206210
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing" />
207-
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
211+
<rule ref="SlevomatCodingStandard.TypeHints.DNFTypeHintFormat">
208212
<properties>
209-
<property name="withSpaces" value="no" />
213+
<property name="withSpacesAroundOperators" value="no" />
210214
<property name="shortNullable" value="yes" />
211215
<property name="nullPosition" value="last" />
212216
</properties>

phpstan.neon

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ parameters:
66
bootstrapFiles:
77
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
88

9-
checkMissingIterableValueType: false
10-
119
ignoreErrors:
1210
-
1311
message: '/Cannot cast mixed to (int|float|string)/'
1412
path: 'src/ArrayCastEnvVarProcessor.php'
13+
-
14+
identifier: missingType.iterableValue
15+
-
16+
identifier: phpDoc.parseError

psalm.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@
2323
<file name=".php-cs-fixer.php" />
2424
</errorLevel>
2525
</UndefinedClass>
26-
27-
<!-- PHPUnit -->
28-
<PropertyNotSetInConstructor>
29-
<errorLevel type="suppress">
30-
<directory name="tests" />
31-
</errorLevel>
32-
</PropertyNotSetInConstructor>
33-
<MissingDependency>
34-
<errorLevel type="suppress">
35-
<directory name="tests" />
36-
</errorLevel>
37-
</MissingDependency>
3826
</issueHandlers>
3927

4028
<plugins>

src/ArrayCastEnvVarProcessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
final class ArrayCastEnvVarProcessor implements EnvVarProcessorInterface
1212
{
13+
#[\Override]
1314
public static function getProvidedTypes(): array
1415
{
1516
return [
@@ -27,6 +28,7 @@ public static function getProvidedTypes(): array
2728
*
2829
* @psalm-suppress MixedReturnTypeCoercion
2930
*/
31+
#[\Override]
3032
public function getEnv(string $prefix, string $name, \Closure $getEnv): array
3133
{
3234
$env = (array) $getEnv($name);
@@ -46,6 +48,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): array
4648
*/
4749
private static function getBooleanMapper(): callable
4850
{
51+
/** @psalm-suppress RiskyTruthyFalsyComparison */
4952
return static fn (mixed $value): bool => (bool) (filter_var($value, \FILTER_VALIDATE_BOOLEAN, ['flags' => \FILTER_NULL_ON_FAILURE]) ?? filter_var($value, \FILTER_VALIDATE_INT) ?: filter_var($value, \FILTER_VALIDATE_FLOAT));
5053
}
5154

@@ -55,6 +58,7 @@ private static function getBooleanMapper(): callable
5558
private static function getIntegerMapper(string $name): callable
5659
{
5760
return static function (mixed $value) use ($name): int {
61+
/** @psalm-suppress RiskyTruthyFalsyComparison */
5862
if ((filter_var($value, \FILTER_VALIDATE_INT) ?: filter_var($value, \FILTER_VALIDATE_FLOAT)) === false) {
5963
throw new RuntimeException('Non-numeric member of environment variable "'.$name.'" cannot be cast to int.');
6064
}

src/CsvEnvVarProcessor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(array $delimiterMap)
2626
$this->delimiterMap = $delimiterMap;
2727
}
2828

29+
#[\Override]
2930
public static function getProvidedTypes(): array
3031
{
3132
// NB
@@ -36,6 +37,7 @@ public static function getProvidedTypes(): array
3637
/**
3738
* @return non-empty-list<string|null>
3839
*/
40+
#[\Override]
3941
public function getEnv(string $prefix, string $name, \Closure $getEnv): array
4042
{
4143
if (\array_key_exists($prefix, $this->delimiterMap) === false) {
@@ -49,6 +51,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): array
4951
throw new RuntimeException('Environment variable "'.$name.'" should be a string.');
5052
}
5153

54+
// @phpstan-ignore greaterOrEqual.alwaysTrue
5255
return str_getcsv($env, $delimiter, '"', \PHP_VERSION_ID >= 70400 ? '' : '\\');
5356
}
5457
}

src/DependencyInjection/NbgroupEnvExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ class NbgroupEnvExtension extends Extension
2020
{
2121
private const NB_REPLACEMENT_MARK = '// NB';
2222

23+
#[\Override]
2324
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
2425
{
2526
return new Configuration();
2627
}
2728

29+
/** @psalm-suppress MixedArrayAccess, MixedArgument */
30+
#[\Override]
2831
public function load(array $configs, ContainerBuilder $container): void
2932
{
3033
$configuration = new Configuration();

tests/ArrayCastEnvVarProcessorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testSuccess(string $prefix, array $envValue, array $expected): v
2929
/**
3030
* @return \Generator<array{string, array, array}>
3131
*/
32-
public function provideSuccessCases(): iterable
32+
public static function provideSuccessCases(): iterable
3333
{
3434
yield 'bool-array' => [
3535
'bool-array',
@@ -82,15 +82,15 @@ public function testInvalidNumeric(string $prefix, array $envValue, string $expe
8282
$processor = new ArrayCastEnvVarProcessor();
8383

8484
$this->expectException(RuntimeException::class);
85-
$this->expectExceptionMessage(sprintf($expectedMessageFormat, 'DM'));
85+
$this->expectExceptionMessage(\sprintf($expectedMessageFormat, 'DM'));
8686

8787
$processor->getEnv($prefix, 'DM', static fn (): array => $envValue);
8888
}
8989

9090
/**
9191
* @return \Generator<array{string, array, string}>
9292
*/
93-
public function provideInvalidNumericCases(): iterable
93+
public static function provideInvalidNumericCases(): iterable
9494
{
9595
yield [
9696
'int-array',
@@ -113,15 +113,15 @@ public function testInvalidBase64(string $prefix, array $envValue, string $expec
113113
$processor = new ArrayCastEnvVarProcessor();
114114

115115
$this->expectException(RuntimeException::class);
116-
$this->expectExceptionMessage(sprintf($expectedMessageFormat, 'DM'));
116+
$this->expectExceptionMessage(\sprintf($expectedMessageFormat, 'DM'));
117117

118118
$processor->getEnv($prefix, 'DM', static fn (): array => $envValue);
119119
}
120120

121121
/**
122122
* @return \Generator<array{string, array, string}>
123123
*/
124-
public function provideInvalidBase64Cases(): iterable
124+
public static function provideInvalidBase64Cases(): iterable
125125
{
126126
yield [
127127
'base64-array',

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ final class ConfigurationTest extends TestCase
2020
/** @var Processor */
2121
private $processor;
2222

23+
protected function setUp(): void
24+
{
25+
$this->processor = new Processor();
26+
}
27+
2328
/**
2429
* @dataProvider provideValidConfigCases
2530
*/
@@ -31,7 +36,7 @@ public function testValidConfig(array $config, array $expected, string $descript
3136
/**
3237
* @return \Generator<array{array, array, string}>
3338
*/
34-
public function provideValidConfigCases(): iterable
39+
public static function provideValidConfigCases(): iterable
3540
{
3641
yield [
3742
[],
@@ -117,7 +122,7 @@ public function testInvalidConfig(array $config, string $expectedMessage): void
117122
/**
118123
* @return \Generator<array{array, string}>
119124
*/
120-
public function provideInvalidConfigCases(): iterable
125+
public static function provideInvalidConfigCases(): iterable
121126
{
122127
yield [
123128
[
@@ -135,9 +140,4 @@ public function provideInvalidConfigCases(): iterable
135140
'Delimiter should be one character only.',
136141
];
137142
}
138-
139-
protected function setUp(): void
140-
{
141-
$this->processor = new Processor();
142-
}
143143
}

0 commit comments

Comments
 (0)