From 3b4c84a2f54b7ae21149b41540e39382b3c741ef Mon Sep 17 00:00:00 2001 From: George Steel Date: Tue, 16 May 2023 10:21:35 +0100 Subject: [PATCH] Apply future Psalm defaults Covers some uncalled methods, removes dead code and updates doc blocks to satisfy newly discovered Psalm issues --- psalm-baseline.xml | 33 +++++++++++++++++++------------ psalm.xml | 22 ++++++--------------- src/Api.php | 1 - src/Document/Fragment/Factory.php | 4 ---- test/Unit/JsonTest.php | 6 ++++++ test/Unit/PredicateTest.php | 1 + test/Unit/Value/FormSpecTest.php | 2 ++ test/Unit/Value/TypeTest.php | 5 +++++ 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a39c7d4..343455c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,32 +1,39 @@ - + + + + withHttpResponse + + - + assert(is_array($configured)) assert(is_array($spec)) is_array($configured) is_array($spec) - is_string($spec['url']) - isset($spec['url']) && is_string($spec['url']) + + + null - + is_array($content) - is_string($spec['token']) - isset($spec['token']) - isset($spec['token']) && is_string($spec['token']) + + + + null - + MissingFile - + $queries $queries - - array<string, array{0: Query, 1: string}> - array<string, array{0: Query, 1: string}> + + ]]> + ]]> diff --git a/psalm.xml b/psalm.xml index 1015d2f..e8b8171 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,10 +2,14 @@ + xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + errorBaseline="psalm-baseline.xml" + findUnusedPsalmSuppress="true" + findUnusedCode="true" + findUnusedBaselineEntry="true" +> @@ -13,20 +17,6 @@ - - - - - - - - - - - - - - diff --git a/src/Api.php b/src/Api.php index 8639cd0..666e5fa 100644 --- a/src/Api.php +++ b/src/Api.php @@ -114,7 +114,6 @@ public static function get( /** * phpcs:disable Generic.Files.LineLength.TooLong, Squiz.Commenting.FunctionComment.SpacingAfterParamType - * @param T|null $instance * @param class-string|class-string|class-string $type * * @template T of object diff --git a/src/Document/Fragment/Factory.php b/src/Document/Fragment/Factory.php index d219497..875e8ce 100644 --- a/src/Document/Fragment/Factory.php +++ b/src/Document/Fragment/Factory.php @@ -29,10 +29,6 @@ final class Factory { use DataAssertionBehaviour; - public function __construct() - { - } - public function __invoke(mixed $data): Fragment { return self::factory($data); diff --git a/test/Unit/JsonTest.php b/test/Unit/JsonTest.php index 25b7803..b3fe992 100644 --- a/test/Unit/JsonTest.php +++ b/test/Unit/JsonTest.php @@ -95,4 +95,10 @@ public function testThatThePayloadIsPreservedByTheException(): void ); } } + + public function testSuccessfulDecode(): void + { + $value = Json::decode('{"foo":"bar"}', true); + self::assertSame(['foo' => 'bar'], $value); + } } diff --git a/test/Unit/PredicateTest.php b/test/Unit/PredicateTest.php index e662031..fec9af0 100644 --- a/test/Unit/PredicateTest.php +++ b/test/Unit/PredicateTest.php @@ -328,6 +328,7 @@ public function testPredicatesCanBeCastToString(string $fragment, string|int|flo /** * @param scalar|list $value * + * @psalm-suppress PossiblyUnusedParam * @dataProvider atProvider */ public function testSetState(string $fragment, string|int|float|bool|array $value, string $expect): void diff --git a/test/Unit/Value/FormSpecTest.php b/test/Unit/Value/FormSpecTest.php index 94b3b66..cd9ffa2 100644 --- a/test/Unit/Value/FormSpecTest.php +++ b/test/Unit/Value/FormSpecTest.php @@ -38,6 +38,8 @@ protected function setUp(): void public function testBasicAccessors(): void { + $this->assertEquals('My Form', $this->form->name()); + $this->assertEquals('something', $this->form->rel()); $this->assertEquals('GET', $this->form->method()); $this->assertEquals('https://example.com', $this->form->action()); $this->assertEquals('whatever', $this->form->encType()); diff --git a/test/Unit/Value/TypeTest.php b/test/Unit/Value/TypeTest.php index 7dd5153..cfa5340 100644 --- a/test/Unit/Value/TypeTest.php +++ b/test/Unit/Value/TypeTest.php @@ -22,6 +22,11 @@ public function testNewInstance(): void public function testJsonEncode(): void { + self::assertEquals( + ['baz' => 'bat'], + Type::new('baz', 'bat')->jsonSerialize(), + ); + self::assertEquals( '{"foo":"bar"}', json_encode(Type::new('foo', 'bar'), JSON_THROW_ON_ERROR),