Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@ jobs:
name: Audit
strategy:
matrix:
php-version: [ '8.2', '8.3' ]
php-version: [ '8.2', '8.3', '8.4' ]
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout (Push)
- name: Checkout
uses: actions/checkout@v4
if: github.event_name == 'push'
with:
fetch-depth: 0

- name: Checkout (PR)
uses: actions/checkout@v4
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -54,13 +44,13 @@ jobs:
echo "::endgroup::"

- name: Auditor
uses: docker://nbgrp/auditor:0.23.1
uses: docker://nbgrp/auditor:0.29.0

- name: Tests
run: vendor/bin/simple-phpunit

- name: Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./clover.xml
3 changes: 3 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
],
'comment_to_phpdoc' => [
'ignored_tags' => [
'codeCoverageIgnoreStart',
'codeCoverageIgnoreEnd',
'codeCoverageIgnore',
'phan-suppress-current-line',
'phan-suppress-next-line',
'see',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"symfony/http-kernel": "^7"
},
"require-dev": {
"phpunit/phpunit": "^11.5",
"roave/security-advisories": "dev-latest",
"symfony/phpunit-bridge": "^7"
},
Expand Down
5 changes: 4 additions & 1 deletion grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ grumphp:
enabled: false

tasks:
composer:
strict: true

composer_normalize:
indent_size: 4
indent_style: 'space'
Expand All @@ -32,4 +35,4 @@ grumphp:
no_cache: true
show_info: true

securitychecker_local: ~
securitychecker_composeraudit: ~
12 changes: 8 additions & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<element value="private methods" />
</property>
</properties>
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing" />
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference" />
Expand Down Expand Up @@ -185,14 +186,17 @@

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="linesCountBeforeDeclare" value="0" />
<property name="linesCountBeforeDeclare" value="1" />
<property name="linesCountAfterDeclare" value="1" />
<property name="spacesCountAroundEqualsSign" value="0" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax">
<properties>
<property name="traversableTypeHints" value="true" />
<property name="traversableTypeHints" type="array">
<element value="Traversable" />
<element value="\ArrayIterator" />
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
Expand All @@ -204,9 +208,9 @@
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing" />
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
<rule ref="SlevomatCodingStandard.TypeHints.DNFTypeHintFormat">
<properties>
<property name="withSpaces" value="no" />
<property name="withSpacesAroundOperators" value="no" />
<property name="shortNullable" value="yes" />
<property name="nullPosition" value="last" />
</properties>
Expand Down
8 changes: 4 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ parameters:
paths:
- src
- tests
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php

checkMissingIterableValueType: false

ignoreErrors:
-
message: '/Cannot cast mixed to (int|float|string)/'
path: 'src/ArrayCastEnvVarProcessor.php'
-
identifier: missingType.iterableValue
-
identifier: phpDoc.parseError
33 changes: 20 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
>
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true"
>

<php>
<ini name="error_reporting" value="-1" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[indirect]=1" />
<server name="SYMFONY_PHPUNIT_VERSION" value="11.5" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=13&amp;max[indirect]=6" />
</php>

<testsuites>
<testsuite name="NbgroupEnvBundle Test Suite">
<directory>./tests/</directory>
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true"
<source ignoreIndirectDeprecations="true"
restrictNotices="true"
restrictWarnings="true"
>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
<exclude>
<file>src/CsvEnvVarProcessor.php</file>
<file>src/NbgroupEnvBundle.php</file>
</exclude>
</source>

<coverage>
<report>
<clover outputFile="clover.xml" />
</report>
Expand Down
12 changes: 0 additions & 12 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,12 @@
</projectFiles>

<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<directory name="tests" />
<file name=".php-cs-fixer.php" />
</errorLevel>
</UndefinedClass>

<!-- PHPUnit -->
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</PropertyNotSetInConstructor>
<MissingDependency>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</MissingDependency>
</issueHandlers>

<plugins>
Expand Down
4 changes: 4 additions & 0 deletions src/ArrayCastEnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

final class ArrayCastEnvVarProcessor implements EnvVarProcessorInterface
{
#[\Override]
public static function getProvidedTypes(): array
{
return [
Expand All @@ -27,6 +28,7 @@ public static function getProvidedTypes(): array
*
* @psalm-suppress MixedReturnTypeCoercion
*/
#[\Override]
public function getEnv(string $prefix, string $name, \Closure $getEnv): array
{
$env = (array) $getEnv($name);
Expand All @@ -46,6 +48,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): array
*/
private static function getBooleanMapper(): callable
{
/** @psalm-suppress RiskyTruthyFalsyComparison */
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));
}

Expand All @@ -55,6 +58,7 @@ private static function getBooleanMapper(): callable
private static function getIntegerMapper(string $name): callable
{
return static function (mixed $value) use ($name): int {
/** @psalm-suppress RiskyTruthyFalsyComparison */
if ((filter_var($value, \FILTER_VALIDATE_INT) ?: filter_var($value, \FILTER_VALIDATE_FLOAT)) === false) {
throw new RuntimeException('Non-numeric member of environment variable "'.$name.'" cannot be cast to int.');
}
Expand Down
5 changes: 5 additions & 0 deletions src/CsvEnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

// @codeCoverageIgnoreStart
if (class_exists(CsvEnvVarProcessor::class, false)) {
return;
}
// @codeCoverageIgnoreEnd

final class CsvEnvVarProcessor implements EnvVarProcessorInterface
{
Expand All @@ -26,6 +28,7 @@
$this->delimiterMap = $delimiterMap;
}

#[\Override]

Check warning on line 31 in src/CsvEnvVarProcessor.php

View check run for this annotation

Codecov / codecov/patch

src/CsvEnvVarProcessor.php#L31

Added line #L31 was not covered by tests
public static function getProvidedTypes(): array
{
// NB
Expand All @@ -36,6 +39,7 @@
/**
* @return non-empty-list<string|null>
*/
#[\Override]

Check warning on line 42 in src/CsvEnvVarProcessor.php

View check run for this annotation

Codecov / codecov/patch

src/CsvEnvVarProcessor.php#L42

Added line #L42 was not covered by tests
public function getEnv(string $prefix, string $name, \Closure $getEnv): array
{
if (\array_key_exists($prefix, $this->delimiterMap) === false) {
Expand All @@ -49,6 +53,7 @@
throw new RuntimeException('Environment variable "'.$name.'" should be a string.');
}

// @phpstan-ignore greaterOrEqual.alwaysTrue
return str_getcsv($env, $delimiter, '"', \PHP_VERSION_ID >= 70400 ? '' : '\\');
}
}
3 changes: 3 additions & 0 deletions src/DependencyInjection/NbgroupEnvExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
{
private const NB_REPLACEMENT_MARK = '// NB';

#[\Override]

Check warning on line 23 in src/DependencyInjection/NbgroupEnvExtension.php

View check run for this annotation

Codecov / codecov/patch

src/DependencyInjection/NbgroupEnvExtension.php#L23

Added line #L23 was not covered by tests
public function getConfiguration(array $config, ContainerBuilder $container): Configuration
{
return new Configuration();
}

/** @psalm-suppress MixedArrayAccess, MixedArgument */
#[\Override]
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand Down
27 changes: 11 additions & 16 deletions tests/ArrayCastEnvVarProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
namespace Nbgrp\Tests\EnvBundle;

use Nbgrp\EnvBundle\ArrayCastEnvVarProcessor;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

/**
* @covers \Nbgrp\EnvBundle\ArrayCastEnvVarProcessor
*
* @internal
*/
#[CoversClass(ArrayCastEnvVarProcessor::class)]
final class ArrayCastEnvVarProcessorTest extends TestCase
{
/**
* @dataProvider provideSuccessCases
*/
#[DataProvider('provideSuccessCases')]
public function testSuccess(string $prefix, array $envValue, array $expected): void
{
$processor = new ArrayCastEnvVarProcessor();
Expand All @@ -29,7 +28,7 @@ public function testSuccess(string $prefix, array $envValue, array $expected): v
/**
* @return \Generator<array{string, array, array}>
*/
public function provideSuccessCases(): iterable
public static function provideSuccessCases(): iterable
{
yield 'bool-array' => [
'bool-array',
Expand Down Expand Up @@ -74,23 +73,21 @@ public function provideSuccessCases(): iterable
];
}

/**
* @dataProvider provideInvalidNumericCases
*/
#[DataProvider('provideInvalidNumericCases')]
public function testInvalidNumeric(string $prefix, array $envValue, string $expectedMessageFormat): void
{
$processor = new ArrayCastEnvVarProcessor();

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

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

/**
* @return \Generator<array{string, array, string}>
*/
public function provideInvalidNumericCases(): iterable
public static function provideInvalidNumericCases(): iterable
{
yield [
'int-array',
Expand All @@ -105,23 +102,21 @@ public function provideInvalidNumericCases(): iterable
];
}

/**
* @dataProvider provideInvalidBase64Cases
*/
#[DataProvider('provideInvalidBase64Cases')]
public function testInvalidBase64(string $prefix, array $envValue, string $expectedMessageFormat): void
{
$processor = new ArrayCastEnvVarProcessor();

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

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

/**
* @return \Generator<array{string, array, string}>
*/
public function provideInvalidBase64Cases(): iterable
public static function provideInvalidBase64Cases(): iterable
{
yield [
'base64-array',
Expand Down
Loading