Skip to content

Commit

Permalink
Merge pull request #276 from netglue/psalm-defaults
Browse files Browse the repository at this point in the history
Apply future Psalm defaults
  • Loading branch information
gsteel committed May 16, 2023
2 parents e165fc3 + be39798 commit 350c51c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 63 deletions.
5 changes: 5 additions & 0 deletions phpcs.xml
Expand Up @@ -24,4 +24,9 @@
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>/test/</exclude-pattern>
</rule>

<!-- PHP 4 Constructors are not possible on PHP 8+ -->
<rule ref="Generic.NamingConventions.ConstructorName.OldStyle">
<severity>0</severity>
</rule>
</ruleset>
34 changes: 5 additions & 29 deletions psalm-baseline.xml
@@ -1,32 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
<file src="test/Smoke/TestCase.php">
<RedundantCondition occurrences="6">
<code>assert(is_array($configured))</code>
<code>assert(is_array($spec))</code>
<code>is_array($configured)</code>
<code>is_array($spec)</code>
<code>is_string($spec['url'])</code>
<code>isset($spec['url']) &amp;&amp; is_string($spec['url'])</code>
</RedundantCondition>
<TypeDoesNotContainType occurrences="4">
<code>is_array($content)</code>
<code>is_string($spec['token'])</code>
<code>isset($spec['token'])</code>
<code>isset($spec['token']) &amp;&amp; is_string($spec['token'])</code>
</TypeDoesNotContainType>
<UnusedPsalmSuppress occurrences="1">
<code>MissingFile</code>
</UnusedPsalmSuppress>
</file>
<file src="test/Unit/QueryTest.php">
<InvalidReturnStatement occurrences="2">
<code>$queries</code>
<code>$queries</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="2">
<code>array&lt;string, array{0: Query, 1: string}&gt;</code>
<code>array&lt;string, array{0: Query, 1: string}&gt;</code>
</InvalidReturnType>
<files psalm-version="5.11.0@c9b192ab8400fdaf04b2b13d110575adc879aa90">
<file src="src/ResultSet/ResultSetFactory.php">
<PossiblyUnusedMethod>
<code>withHttpResponse</code>
</PossiblyUnusedMethod>
</file>
</files>
22 changes: 6 additions & 16 deletions psalm.xml
Expand Up @@ -2,31 +2,21 @@
<psalm
errorLevel="1"
memoizeMethodCallResults="true"
findUnusedPsalmSuppress="true"
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">
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
findUnusedPsalmSuppress="true"
findUnusedCode="true"
findUnusedBaselineEntry="true"
>
<projectFiles>
<directory name="src"/>
<directory name="test"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<InternalMethod>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::method"/>
</errorLevel>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn"/>
</errorLevel>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::with"/>
</errorLevel>
</InternalMethod>
</issueHandlers>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
Expand Down
1 change: 0 additions & 1 deletion src/Api.php
Expand Up @@ -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<ClientInterface>|class-string<RequestFactoryInterface>|class-string<UriFactoryInterface> $type
*
* @template T of object
Expand Down
4 changes: 0 additions & 4 deletions src/Document/Fragment/Factory.php
Expand Up @@ -29,10 +29,6 @@ final class Factory
{
use DataAssertionBehaviour;

public function __construct()
{
}

public function __invoke(mixed $data): Fragment
{
return self::factory($data);
Expand Down
1 change: 0 additions & 1 deletion test/Smoke/TestCase.php
Expand Up @@ -64,7 +64,6 @@ protected static function compileEndPoints(): array
return $endpoints;
}

/** @psalm-suppress MissingFile */
$content = require $configPath;
if (! is_array($content)) {
return $endpoints;
Expand Down
6 changes: 6 additions & 0 deletions test/Unit/JsonTest.php
Expand Up @@ -95,4 +95,10 @@ public function testThatThePayloadIsPreservedByTheException(): void
);
}
}

public function testSuccessfulDecode(): void
{
$value = Json::decode('{"foo":"bar"}', true);
self::assertSame(['foo' => 'bar'], $value);
}
}
1 change: 1 addition & 0 deletions test/Unit/PredicateTest.php
Expand Up @@ -328,6 +328,7 @@ public function testPredicatesCanBeCastToString(string $fragment, string|int|flo
/**
* @param scalar|list<scalar> $value
*
* @psalm-suppress PossiblyUnusedParam
* @dataProvider atProvider
*/
public function testSetState(string $fragment, string|int|float|bool|array $value, string $expect): void
Expand Down
40 changes: 28 additions & 12 deletions test/Unit/QueryTest.php
Expand Up @@ -69,12 +69,20 @@ public static function queryProvider(): array
/** @return array<string, array{0: Query, 1: string}> */
public static function defaultUrlProvider(): array
{
$queries = self::queryProvider();
$queries['Standard Form'][1] = 'https://example.com/api/v2?page=1&pageSize=20';
$queries['Collection'][1] = sprintf('https://example.com?q=%s&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]'));
$queries['With Query'][1] = 'https://example.com/?term=something&page=1&pageSize=20';

return $queries;
return [
'Standard Form' => [
new Query(FormSpec::factory('everything', self::formData()->everything)),
'https://example.com/api/v2?page=1&pageSize=20',
],
'With Query' => [
new Query(FormSpec::factory('withQuery', self::formData()->withQuery)),
'https://example.com/?term=something&page=1&pageSize=20',
],
'Collection' => [
new Query(FormSpec::factory('collection', self::formData()->collection)),
sprintf('https://example.com?q=%s&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]')),
],
];
}

/** @dataProvider defaultUrlProvider */
Expand All @@ -86,12 +94,20 @@ public function testDefaultUrl(Query $query, string $expectedUrl): void
/** @return array<string, array{0: Query, 1: string}> */
public static function queryUrlProvider(): array
{
$queries = self::queryProvider();
$queries['Standard Form'][1] = 'https://example.com/api/v2?page=1&pageSize=20&q=foo';
$queries['Collection'][1] = sprintf('https://example.com?q=%s&q=foo&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]'));
$queries['With Query'][1] = 'https://example.com/?term=something&page=1&pageSize=20&q=foo';

return $queries;
return [
'Standard Form' => [
new Query(FormSpec::factory('everything', self::formData()->everything)),
'https://example.com/api/v2?page=1&pageSize=20&q=foo',
],
'With Query' => [
new Query(FormSpec::factory('withQuery', self::formData()->withQuery)),
'https://example.com/?term=something&page=1&pageSize=20&q=foo',
],
'Collection' => [
new Query(FormSpec::factory('collection', self::formData()->collection)),
sprintf('https://example.com?q=%s&q=foo&page=1&pageSize=20', urlencode('[[:d = any(document.type, ["doc-type"])]]')),
],
];
}

/** @dataProvider queryUrlProvider */
Expand Down
2 changes: 2 additions & 0 deletions test/Unit/Value/FormSpecTest.php
Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions test/Unit/Value/TypeTest.php
Expand Up @@ -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),
Expand Down

0 comments on commit 350c51c

Please sign in to comment.