Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropping @psalm-self-out to avoid incorrect type inference in inheritance #78

Merged
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
40 changes: 6 additions & 34 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
<DocblockTypeContradiction occurrences="1">
<code>! is_array($data) &amp;&amp; ! is_object($data)</code>
</DocblockTypeContradiction>
<InvalidArgument occurrences="2">
<code>$key</code>
<code>$value</code>
</InvalidArgument>
<InvalidPropertyAssignmentValue occurrences="2">
<code>$data</code>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$this-&gt;storage</code>
</InvalidPropertyAssignmentValue>
<MixedArgument occurrences="1">
<code>$v</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$v</code>
</MixedAssignment>
Expand Down Expand Up @@ -100,14 +98,12 @@
<ImplementedReturnTypeMismatch occurrences="1">
<code>TValue|int|array{data: TValue|false, priority: int}|false</code>
</ImplementedReturnTypeMismatch>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$this-&gt;values</code>
</InvalidPropertyAssignmentValue>
<LessSpecificReturnStatement occurrences="3">
<code>$array</code>
<code>$value</code>
</LessSpecificReturnStatement>
<MixedArgument occurrences="1">
<MixedArgument occurrences="2">
<code>$item['data']</code>
<code>$item['priority']</code>
</MixedArgument>
<MixedArrayAccess occurrences="2">
Expand Down Expand Up @@ -172,32 +168,13 @@
<code>setMetadata</code>
</MissingReturnType>
</file>
<file src="src/Parameters.php">
<InvalidArgument occurrences="3">
<code>$name</code>
<code>$name</code>
<code>$value</code>
</InvalidArgument>
<MixedArgumentTypeCoercion occurrences="1">
<code>$this-&gt;toArray()</code>
</MixedArgumentTypeCoercion>
<MoreSpecificImplementedParamType occurrences="1">
<code>$name</code>
</MoreSpecificImplementedParamType>
</file>
<file src="src/PriorityList.php">
<FalsableReturnStatement occurrences="1">
<code>$node ? $node['data'] : false</code>
</FalsableReturnStatement>
<InvalidArrayOffset occurrences="1">
<code>$this-&gt;items[$name]</code>
</InvalidArrayOffset>
<InvalidFalsableReturnType occurrences="1">
<code>current</code>
</InvalidFalsableReturnType>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$this-&gt;items</code>
</InvalidPropertyAssignmentValue>
<InvalidReturnStatement occurrences="1">
<code>$node ? $node['data'] : false</code>
</InvalidReturnStatement>
Expand Down Expand Up @@ -466,11 +443,6 @@
</UndefinedPropertyFetch>
</file>
<file src="test/PriorityListTest.php">
<MixedAssignment occurrences="3">
<code>$orders1[$this-&gt;list-&gt;key()]</code>
<code>$orders2[$key]</code>
<code>$value</code>
</MixedAssignment>
<NullArgument occurrences="5">
<code>null</code>
<code>null</code>
Expand Down
18 changes: 4 additions & 14 deletions src/ArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ public function __isset(mixed $key)
/**
* Sets the value at the specified key to value
*
* @template TInputKey of array-key
* @template TInputValue
* @param TInputKey $key
* @param TInputValue $value
* @psalm-self-out ArrayObject<TKey|TInputKey, TValue|TInputValue>
* @param TKey $key
* @param TValue $value
* @return void
*/
public function __set(mixed $key, mixed $value)
Expand Down Expand Up @@ -173,9 +170,7 @@ public function &__get(mixed $key)
/**
* Appends the value
*
* @template TInputValue
* @param TInputValue $value
* @psalm-self-out ArrayObject<TKey|int, TValue|TInputValue>
* @param TValue $value
* @return void
*/
public function append(mixed $value)
Expand Down Expand Up @@ -207,12 +202,7 @@ public function count()
/**
* Exchange the array for another one.
*
* @template TInputKey of array-key
* @template TInputValue
* // phpcs:disable Generic.Files.LineLength.TooLong
* @param array<TInputKey, TInputValue>|ArrayObject<TInputKey, TInputValue>|ArrayIterator<TInputKey, TInputValue>|object $data
* // phpcs:enable Generic.Files.LineLength.TooLong
* @psalm-self-out ArrayObject<TInputKey, TInputValue>
* @param array<TKey, TValue>|ArrayObject<TKey, TValue>|ArrayIterator<TKey, TValue>|object $data
* @return array<TKey, TValue>
*/
public function exchangeArray($data)
Expand Down
6 changes: 2 additions & 4 deletions src/FastPriorityQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ public function __unserialize(array $data): void
/**
* Insert an element in the queue with a specified priority
*
* @template TInputValue
* @param TInputValue $value
* @param int $priority
* @psalm-self-out FastPriorityQueue<TValue|TInputValue>
* @param TValue $value
* @param int $priority
* @return void
*/
public function insert(mixed $value, $priority)
Expand Down
15 changes: 4 additions & 11 deletions src/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use function parse_str;

/**
* @template TKey
* @template TKey of array-key
* @template TValue
* @template-extends PhpArrayObject<TKey, TValue>
* @template-implements ParametersInterface<TKey, TValue>
Expand All @@ -37,10 +37,7 @@ public function __construct(?array $values = null)
/**
* Populate from native PHP array
*
* @template TInputKey of array-key
* @template TInputValue
* @param array<TInputKey, TInputValue> $values
* @psalm-self-out Parameters<TInputKey, TInputValue>
* @param array<TKey, TValue> $values
* @return void
*/
public function fromArray(array $values)
Expand All @@ -52,7 +49,6 @@ public function fromArray(array $values)
* Populate from query string
*
* @param string $string
* @psalm-self-out Parameters<array-key, mixed>
* @return void
*/
public function fromString($string)
Expand Down Expand Up @@ -115,11 +111,8 @@ public function get($name, $default = null)
}

/**
* @template TInputKey of array-key
* @template TInputValue
* @param TInputKey $name
* @param TInputValue $value
* @psalm-self-out Parameters<TKey|TInputKey, TValue|TInputValue>
* @param TKey $name
* @param TValue $value
* @return $this
*/
public function set($name, $value)
Expand Down
2 changes: 1 addition & 1 deletion src/ParametersInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(?array $values = null);
*
* Allow deserialization from standard array
*
* @param array $values
* @param array<TKey, TValue> $values
* @return mixed
*/
public function fromArray(array $values);
Expand Down
9 changes: 3 additions & 6 deletions src/PriorityList.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ class PriorityList implements Iterator, Countable
/**
* Insert a new item.
*
* @template TInputKey of string
* @template TInputValue
* @param TInputKey $name
* @param TInputValue $value
* @param int $priority
* @psalm-self-out PriorityList<TInputKey|TKey, TInputValue|TValue>
* @param TKey $name
* @param TValue $value
* @param int $priority
* @return void
*/
public function insert($name, mixed $value, $priority = 0)
Expand Down
3 changes: 3 additions & 0 deletions test/ArrayObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function testConstructorParameters(): void

public function testStdPropList(): void
{
/** @var ArrayObject<string, string> $ar */
$ar = new ArrayObject();
$ar->foo = 'bar';
$ar->bar = 'baz';
Expand Down Expand Up @@ -96,6 +97,7 @@ public function testArrayAsProps(): void

public function testAppend(): void
{
/** @var ArrayObject<int, string> $ar */
$ar = new ArrayObject(['one', 'two']);
self::assertEquals(2, $ar->count());

Expand Down Expand Up @@ -131,6 +133,7 @@ public function testCountable(): void

public function testExchangeArray(): void
{
/** @var ArrayObject<string, string> $ar */
$ar = new ArrayObject(['foo' => 'bar']);
$old = $ar->exchangeArray(['bar' => 'baz']);

Expand Down