Conversation
src/AssocArray.php
Outdated
| */ | ||
| public function flip(): IterableValue | ||
| { | ||
| return $this->toIterableValue()->flip(); |
There was a problem hiding this comment.
Why not through GW\Value\Associable\Flip? I don't think that AssocArray should return IterableValue.
There was a problem hiding this comment.
It is hard to flip AssocValue, because TKey must be int|string and TValue is mixed - therefore it produces phpstan type errors. I think it can be fully fixed only after rewrite AssocValue to some kind of map with mixed key and mixed value.
For now I've changed it to:
/**
* @phpstan-return AssocValue<int|string, TKey>
*/
public function flip(): AssocValue;it will be AssocValue - not AssocValue<TValue,TKey> but AssocValue<int|string, TKey>
in other words - you loose type for key - from Wrap::assoc([0 => 'xxx']) as AssocValue<int,string> flip makes AssocValue<int|string,int>, not AssocValue<string,int>
| } | ||
|
|
||
| /** | ||
| * @phpstan-return AssocValue<int|string, TKey> |
There was a problem hiding this comment.
It can't be AssocValue<TValue, TKey>?
I know it doesn't make sense if TValue isn't int|string, but AssocValue<int, string> flipped should be rather AssocValue<string, int> than AssocValue<int|string, int>
| * @param TKey $keyB | ||
| * @phpstan-return AssocArray<TKey, TValue> | ||
| */ | ||
| public function swap($keyA, $keyB): AssocArray; |
There was a problem hiding this comment.
It can have type-hint int|string for arguments, and return should be AssocValue
| * @param TKey $keyA | ||
| * @param TKey $keyB | ||
| */ | ||
| public function __construct(Associable $associable, $keyA, $keyB) |
| /** | ||
| * @param string|StringValue $pattern | ||
| * @return ArrayValue<array<int|string, string>> | ||
| * @return ArrayValue<array<string>> |
There was a problem hiding this comment.
It can be array<int|string, string> when there's named subpattern
(?P<name>lorem) => [0 => 'lorem', 'name' => 'lorem', 1 => 'lorem']
There was a problem hiding this comment.
I think I has similar problem on my branch and resolved it like this 😏
No description provided.