diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c7bf82be57e66c0cdef65b705f822943aca0c12a..ac73b00e1b6d66ff291a989ad601f54568ae010d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout Code diff --git a/composer.json b/composer.json index 77f50a37f5127acd0c498bef0ececd1eccb057ef..91dd6fb721939498bce052e5edcb691537f27dd2 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", - "phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2" + "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28" }, "autoload": { "psr-4": { @@ -41,12 +41,10 @@ "extra": { "bamarni-bin": { "bin-links": true, - "forward-command": true + "forward-command": false }, "branch-alias": { "dev-master": "1.9-dev" } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dda1b4a282dab573ced35c189591594ba5fd8589..5310bd232ade68156c9389b78750667c953a3042 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -21,7 +21,7 @@ parameters: path: src/PhpOption/Option.php - - message: "#^Parameter \\#2 \\$callback of function array_reduce expects callable\\(mixed, mixed\\)\\: mixed, Closure\\(mixed, PhpOption\\\\Option\\)\\: mixed given\\.$#" + message: "#^Parameter \\#2 \\$callback of function array_reduce expects callable\\(bool\\|TReturn, mixed\\)\\: \\(bool\\|TReturn\\), Closure\\(mixed, PhpOption\\\\Option\\)\\: \\(bool\\|TReturn\\) given\\.$#" count: 1 path: src/PhpOption/Option.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fd7a64612250a95d1c51ded313f6e7dec380d636..6f8227f54e043742df803ba38796c422a7af856a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,4 +5,3 @@ parameters: level: max paths: - src - checkGenericClassInNonGenericObjectType: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ae1c4731189bb8428b2bbc08ea8a9271c22a553a..14025a68f01d4e78ae74ffec4d4907a97eecfb37 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="tests/bootstrap.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"> +<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="tests/bootstrap.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"> <testsuites> <testsuite name="PhpOption Type Test Suite"> <directory>./tests/PhpOption/</directory> diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000000000000000000000000000000000000..7bf39a80e9392de55a3d7a9d6a88123df4a62c3a --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505"/> diff --git a/psalm.xml b/psalm.xml index db645bca98180ad17a9fcce9f502df9f9d6fc20b..7ee17a8b4f27fab2c76e144ab02f37eb9fada4bd 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,6 +5,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + errorBaseline="psalm-baseline.xml" + findUnusedBaselineEntry="true" + findUnusedCode="false" > <projectFiles> <directory name="src" /> diff --git a/src/PhpOption/Option.php b/src/PhpOption/Option.php index 172924cf4e7f2a942e81fedd3130f40b28e29281..91fab9ca6b344191ce6f650eaaa1f0ab0bec5a75 100644 --- a/src/PhpOption/Option.php +++ b/src/PhpOption/Option.php @@ -62,13 +62,13 @@ abstract class Option implements IteratorAggregate * @template S * * @param array<string|int,S>|ArrayAccess<string|int,S>|null $array A potential array or \ArrayAccess value. - * @param string $key The key to check. + * @param string|int|null $key The key to check. * * @return Option<S> */ public static function fromArraysValue($array, $key) { - if (!(is_array($array) || $array instanceof ArrayAccess) || !isset($array[$key])) { + if ($key === null || !(is_array($array) || $array instanceof ArrayAccess) || !isset($array[$key])) { return None::create(); } diff --git a/tests/PhpOption/Tests/OptionTest.php b/tests/PhpOption/Tests/OptionTest.php index d386ff28be4d09b041e340ce3096a529f9b5e52f..4e31b928cadaca239d9d8e6ab6d8a8215ab01977 100644 --- a/tests/PhpOption/Tests/OptionTest.php +++ b/tests/PhpOption/Tests/OptionTest.php @@ -31,11 +31,17 @@ class OptionTest extends TestCase self::assertEquals(None::create(), Option::fromArraysValue(null, 'bar')); self::assertEquals(None::create(), Option::fromArraysValue(['foo' => 'bar'], 'baz')); self::assertEquals(None::create(), Option::fromArraysValue(['foo' => null], 'foo')); + self::assertEquals(None::create(), Option::fromArraysValue(['foo' => 'bar'], null)); self::assertEquals(new Some('foo'), Option::fromArraysValue(['foo' => 'foo'], 'foo')); + self::assertEquals(new Some('foo'), Option::fromArraysValue([13 => 'foo'], 13)); $object = new SomeArrayObject(); $object['foo'] = 'foo'; self::assertEquals(new Some('foo'), Option::fromArraysValue($object, 'foo')); + + $object = new SomeArrayObject(); + $object[13] = 'foo'; + self::assertEquals(new Some('foo'), Option::fromArraysValue($object, 13)); } public function testFromReturn(): void diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json index d572d14fe0ee1b332e1e249e63c6f36aafb440e6..e24f98245d156adce4d91a67a2e01aa1b2af926f 100644 --- a/vendor-bin/phpstan/composer.json +++ b/vendor-bin/phpstan/composer.json @@ -1,6 +1,6 @@ { "require": { - "phpstan/phpstan": "1.10.41" + "phpstan/phpstan": "1.11.7" }, "config": { "preferred-install": "dist" diff --git a/vendor-bin/psalm/composer.json b/vendor-bin/psalm/composer.json index c87e133156e2ffe2d73c1451bf8cd78cd0539d3b..5aceaa617706dca2db843ecfb961fa31022b9507 100644 --- a/vendor-bin/psalm/composer.json +++ b/vendor-bin/psalm/composer.json @@ -1,6 +1,6 @@ { "require": { - "psalm/phar": "5.15.0" + "psalm/phar": "5.25.0" }, "config": { "preferred-install": "dist"