Skip to content

Commit

Permalink
satisfying static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
SignpostMarv committed Feb 20, 2019
1 parent 0fd0d8e commit 3732d8e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
class AbstractDaftObjectImplementationTest extends DaftObjectImplementationTest
{
/**
* @return Generator<int, array{0:class-string<AbstractDaftObject>, 1:string}, mixed, void>
*/
public function dataProvider_FuzzingImplementations_NotPublicGetter() : Generator
{
foreach ($this->dataProviderNonAbstractGoodFuzzing() as $args) {
Expand All @@ -38,6 +41,9 @@ public function dataProvider_FuzzingImplementations_NotPublicGetter() : Generato
}
}

/**
* @return Generator<int, array{0:class-string<AbstractDaftObject>, 1:string}, mixed, void>
*/
public function dataProvider_FuzzingImplementations_NotPublicSetter() : Generator
{
foreach ($this->dataProviderNonAbstractGoodFuzzing() as $args) {
Expand All @@ -55,6 +61,9 @@ public function dataProvider_FuzzingImplementations_NotPublicSetter() : Generato
}
}

/**
* @return Generator<int, array{0:class-string<AbstractDaftObject>, 1:string}, mixed, void>
*/
public function dataProvider_FuzzingImplementations_NotDefined() : Generator
{
foreach ($this->dataProviderNonAbstractGoodFuzzing() as $args) {
Expand Down
6 changes: 6 additions & 0 deletions Tests/DaftJson/DaftJsonExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
class DaftJsonExceptionTest extends TestCase
{
/**
* @psalm-return array<int, array{0:class-string<DaftObject>, 1:string, 2:array<string, scalar|array|object|null>, 3:bool}>
*/
public function dataProviderClassDoesNotImplementClassException() : array
{
return [
Expand All @@ -43,6 +46,9 @@ public function dataProviderClassDoesNotImplementClassException() : array
];
}

/**
* @psalm-return array<int, array{0:class-string<DaftObject>, 1:class-string<DaftObject>, 2:string, 3:class-string<\Throwable>, 4:string, 5:array<string, scalar|array|object|null>, 6:bool}>
*/
public function dataProviderPropertyNotThingableException() : array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion Tests/DaftJson/JsonTypeUtilitiesExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function test_DaftObjectFromJsonTypeArray_fails_with_non_array() : void
}

/**
* @psalm-return array<int, array{0:class-string<DaftJson>, 1:array, 2:class-string<\Throwable>, 2:string}>
* @psalm-return array<int, array{0:class-string<DaftJson>, 1:array, 2:class-string<\Throwable>, 3:string}>
*/
public function dataProvider_ThrowIfJsonDefNotValid_fails() : array
{
Expand Down
32 changes: 3 additions & 29 deletions Tests/DaftObject/DaftObjectImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,21 +1252,9 @@ final public function testNonAbstractGoodFuzzingHasSettersPerPropertyNotNullable
}
}

final public function dataProviderDaftObjectCreatedByArray() : Generator
{
foreach ($this->dataProviderNonAbstractGoodImplementations() as $args) {
if (
is_array($args) &&
count($args) >= 1 &&
is_string($args[0]) &&
is_a($args[0], DaftObjectCreatedByArray::class, true)
) {
yield [$args[0], true];
yield [$args[0], false];
}
}
}

/**
* @return Generator<int, array{0:class-string<AbstractDaftObject>}, mixed, void>
*/
final public function DataProviderNotDaftObjectHasPropertiesWithMultiTypedArraysOfUniqueValues(
) : Generator {
foreach ($this->dataProviderImplementations() as $args) {
Expand Down Expand Up @@ -1853,18 +1841,4 @@ protected function FuzzingImplementationsViaGenerator() : Generator
{
yield from $this->FuzzingImplementationsViaArray();
}

/**
* @psalm-return Generator<int, array{0:class-string<T&DaftSortableObject>, 1:ReflectionClass, 2:array<string, scalar|array|object|null>, 3:array<int, string>, 4:array<int, string>}, mixed, void>
*/
protected function SortableFuzzingImplementationsViaGenerator() : Generator
{
foreach ($this->dataProviderNonAbstractGoodFuzzing() as $args) {
if (
is_a($args[0], DaftSortableObject::class)
) {
yield $args;
}
}
}
}
25 changes: 18 additions & 7 deletions Tests/DaftObject/MultiTypedArrayPropertyImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class MultiTypedArrayPropertyImplementationTest extends TestCase
{
/**
* @return Generator<int, array{0: MultiTypedArrayPropertiesTester, 1:string, 2:scalar|array|object|null, 3:class-string<\Throwable>, 4:string}, mixed, void>
*/
public function DataProviderObjectPropertyValueException() : Generator
{
yield from [
Expand Down Expand Up @@ -58,21 +61,26 @@ public function DataProviderObjectPropertyValueException() : Generator
];
}

/**
* @return Generator<int, array{0:MultiTypedArrayPropertiesTester, 1:string, 2:array<int, mixed>}, mixed, void>
*/
public function DataProviderObjectPropertyValueNotUniqueAutoDouble() : Generator

This comment has been minimized.

Copy link
@SignpostMarv

SignpostMarv Feb 20, 2019

Author Owner

@weirdan this is the generator that now triggers MoreSpecificReturnType

This comment has been minimized.

Copy link
@weirdan

weirdan Feb 21, 2019

Well, that was failing on getpsalm (where there's no phpunit plugin) as well. It appears psalm has problems deducing $args[2] to be array from that assert. If you put it into a var, it works fine (and you don't need those array casts): https://getpsalm.org/r/0e5099592b

This comment has been minimized.

Copy link
@weirdan
{
/**
* @var iterable<array<int, mixed>>
*/
$sources = $this->DataProviderObjectPropertyValueNotUnique();

foreach ($sources as $args) {
foreach ($this->DataProviderObjectPropertyValueNotUnique() as $args) {
static::assertIsArray($args[2] ?? null);
$args[2] = array_merge(array_values((array) $args[2]), array_values((array) $args[2]));
/**
* @var array<int, mixed>
*/
$args_2 = array_merge(array_values((array) $args[2]), array_values((array) $args[2]));
$args[2] = $args_2;

yield $args;
}
}

/**
* @return Generator<int, array{0:MultiTypedArrayPropertiesTester, 1:string, 2:scalar|array|object|null, 3:scalar|array|object|null}, mixed, void>
*/
public function DataProviderObjectPropertyValueTrimmedStrings() : Generator
{
yield from [
Expand Down Expand Up @@ -146,6 +154,9 @@ public function testAutoTrimmedStrings(
static::assertSame($expected, $obj->__get($property));
}

/**
* @return Generator<int, array{0:MultiTypedArrayPropertiesTester, 1:string, 2:scalar|array|object|null}, mixed, void>
*/
protected function DataProviderObjectPropertyValueNotUnique() : Generator
{
yield from [
Expand Down
6 changes: 6 additions & 0 deletions Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ final public function dataProvider_DaftObject__interface__has_properties() : Gen
}
}

/**
* @psalm-return Generator<int, array{0:class-string<DaftObject>}, mixed, void>
*/
public function dataProvider_DaftObject__has_properties() : Generator
{
yield from $this->dataProvider_AbstractDaftObject__has_properties();
Expand Down Expand Up @@ -403,6 +406,9 @@ final public function dataProvider_DaftObject__interface__has_properties_each_de
}
}

/**
* @psalm-return Generator<string, array{0:class-string<AbstractDaftObject>, 1:string}, mixed, void>
*/
public function dataProvider_DaftObject__has_properties_each_defined_property() : Generator
{
yield from $this->dataProvider_AbstractDaftObject__has_properties_each_defined_property();
Expand Down
40 changes: 6 additions & 34 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files>
<file src="Tests\AbstractDaftObject\AbstractDaftObjectImplementationTest.php">
<InvalidReturnType occurrences="3">
<code>Generator</code>
<code>Generator</code>
<code>Generator</code>
</InvalidReturnType>
</file>
<file src="Tests\DaftJson\DaftJsonExceptionTest.php">
<InvalidReturnType occurrences="2">
<code>array</code>
<code>array</code>
</InvalidReturnType>
</file>
<file src="Tests\DaftJson\JsonTypeUtilitiesExceptionsTest.php">
<InvalidArgument occurrences="1">
<code>@dataProvider dataProvider_ThrowIfJsonDefNotValid_fails</code>
<InvalidArgument occurrences="2">
<code>@dataProvider dataProviderClassDoesNotImplementClassException</code>
<code>@dataProvider dataProviderPropertyNotThingableException</code>
</InvalidArgument>
<TooFewArguments occurrences="1">
<code>@dataProvider dataProvider_ThrowIfJsonDefNotValid_fails</code>
</TooFewArguments>
</file>
<file src="Tests\DaftObject\DaftObjectImplementationTest.php">
<InvalidArgument occurrences="6">
Expand All @@ -30,20 +15,11 @@
<code>@dataProvider dataProviderNonAbstractGoodFuzzingHasSettersPerPropertyNotNullable</code>
<code>@dataProvider dataProviderNonAbstractGoodSortableImplementations</code>
</InvalidArgument>
<InvalidReturnType occurrences="1">
<code>Generator</code>
</InvalidReturnType>
<PossiblyUnusedMethod occurrences="2">
<code>final public function dataProviderDaftObjectCreatedByArray() : Generator</code>
<code>protected function SortableFuzzingImplementationsViaGenerator() : Generator</code>
</PossiblyUnusedMethod>
</file>
<file src="Tests\DaftObject\MultiTypedArrayPropertyImplementationTest.php">
<InvalidReturnType occurrences="3">
<code>Generator</code>
<code>Generator</code>
<code>Generator</code>
</InvalidReturnType>
<MoreSpecificReturnType occurrences="1">

This comment has been minimized.

Copy link
@SignpostMarv

SignpostMarv Feb 20, 2019

Author Owner

@weirdan this issue doesn't crop up on master branch :s

<code>@return Generator&lt;int, array{0:MultiTypedArrayPropertiesTester, 1:string, 2:array&lt;int, mixed&gt;}, mixed, void&gt;</code>
</MoreSpecificReturnType>
</file>
<file src="Tests\DaftSortableObject\DaftSortableObjectTest.php">
<InvalidArgument occurrences="1">
Expand Down Expand Up @@ -74,10 +50,6 @@
</InvalidArgument>
</file>
<file src="Tests\TestCase.php">
<InvalidReturnType occurrences="2">
<code>Generator</code>
<code>Generator</code>
</InvalidReturnType>
<UnusedProperty occurrences="3">
<code>$backupGlobals</code>
<code>$backupStaticAttributes</code>
Expand Down

0 comments on commit 3732d8e

Please sign in to comment.