WIP update Stan to lvl6#1
Conversation
8b1baff to
c5870e3
Compare
| /** | ||
| * @return array<string,mixed> | ||
| * | ||
| * @psalm-suppress PossiblyUnusedMethod |
There was a problem hiding this comment.
@mplesa1 this method is used inside the project, how come Psalm recognizes it as unused?
| * | ||
| * @throws JsonApiEncodingException | ||
| * | ||
| * @psalm-suppress PossiblyUnusedMethod |
There was a problem hiding this comment.
Even though it's used, Psalm recognizes it as unused?
There was a problem hiding this comment.
I removed the annotation because it's also used inside PhpArrayToRelationshipCollectionEncoder. But yes, if it's only used inside some test we need annotation.
|
|
||
| use Undabot\JsonApi\Definition\Model\Resource\ResourceInterface; | ||
|
|
||
| /** @psalm-suppress UnusedClass */ |
There was a problem hiding this comment.
Psalm documentation says the following:
If this class is used and part of the public API, annotate it with @psalm-api.
I believe we should check all of the classes that are used as part of json-api-symfony and mark them with @psalm-api instead of suppressing the error.
| $rawMeta = $resource['meta'] ?? null; | ||
| $rawLink = $resource['links']['self'] ?? null; | ||
|
|
||
| $rawAttributes = $this->assertStringKeyArray($resource['attributes'] ?? []); |
There was a problem hiding this comment.
What do you think about adding a string $key to this method, resulting in the coalescing operator being moved to the assertStringKeyArray method to avoid doing it outside on each call to the method?
There was a problem hiding this comment.
agree, good catch, I refactored both assertStringKeyArray and assertStringKeyArrayNested
| private function assertStringKeyArray(mixed $array): array | ||
| { | ||
| if (!is_array($array)) { | ||
| throw new \InvalidArgumentException("Parameter is not array."); | ||
| } | ||
| foreach ($array as $key) { | ||
| if (!is_string($key)) { | ||
| throw new \InvalidArgumentException("Array key must be a string."); | ||
| } | ||
| } | ||
|
|
||
| return $array; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @param mixed $array | ||
| * @return array<string, array<string, mixed>> | ||
| */ | ||
| function assertStringKeyArrayNested(mixed $array): array |
There was a problem hiding this comment.
These methods could be moved to some sort of a utility class if we're going to need them in more places?
There was a problem hiding this comment.
Yes, I move them to the existing abstract class ArrayUtil
| class SortSet implements \IteratorAggregate | ||
| { | ||
| /** @var Sort[] */ | ||
| private $sorts; |
| { | ||
| /** @var Attribute[] */ | ||
| /** @var AttributeInterface[] */ | ||
| private $attributes; |
| { | ||
| /** @var array */ | ||
| /** @var RelationshipInterface[] */ | ||
| private $relationships = []; |
| // $message = sprintf('ResourceIdentifierInterface expected, %s given', \get_class($resourceIdentifier)); | ||
| // | ||
| // throw new InvalidArgumentException($message); |
There was a problem hiding this comment.
I don't know, @KondukterCRO did those changes in this branch d05ac8b#diff-390909c32070ee11ae2baba70ca5c9e766a3b2bf1a3a2297dd63ddde7a79f4db Pena, do you have some information?
| // $message = sprintf('ResourceIdentifierInterface expected, %s given', \get_class($resourceIdentifier)); | ||
| // | ||
| // throw new InvalidArgumentException($message); |
…nEncoderInterface
…th adding key param and handle null
| interface LinkToPhpArrayEncoderInterface | ||
| { | ||
| /** | ||
| * @return null|array<string,mixed>|string |
Description:
Updating PHPStan to lvl6