1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Inspirum\Balikobot\Model\Carrier; |
||
6 | |||
7 | use Inspirum\Arrayable\BaseModel; |
||
8 | use Inspirum\Balikobot\Model\Method\MethodCollection; |
||
9 | use function array_map; |
||
10 | |||
11 | /** |
||
12 | * @extends \Inspirum\Arrayable\BaseModel<string,mixed> |
||
13 | */ |
||
14 | final class DefaultCarrier extends BaseModel implements Carrier |
||
15 | { |
||
16 | /** |
||
17 | * @param array<string,\Inspirum\Balikobot\Model\Method\MethodCollection> $methods |
||
18 | */ |
||
19 | 13 | public function __construct( |
|
20 | private readonly string $code, |
||
21 | private readonly string $name, |
||
22 | private readonly array $methods = [], |
||
23 | ) { |
||
24 | 13 | } |
|
25 | |||
26 | 7 | public function getCode(): string |
|
27 | { |
||
28 | 7 | return $this->code; |
|
29 | } |
||
30 | |||
31 | 1 | public function getName(): string |
|
32 | { |
||
33 | 1 | return $this->name; |
|
34 | } |
||
35 | |||
36 | /** @inheritDoc */ |
||
37 | 1 | public function getMethods(): array |
|
38 | { |
||
39 | 1 | return $this->methods; |
|
40 | } |
||
41 | |||
42 | 2 | public function getMethodsForVersion(string $version): MethodCollection |
|
43 | { |
||
44 | 2 | return $this->methods[$version]; |
|
45 | } |
||
46 | |||
47 | /** @inheritDoc */ |
||
48 | 3 | public function __toArray(): array |
|
49 | { |
||
50 | 3 | return [ |
|
0 ignored issues
–
show
|
|||
51 | 3 | 'code' => $this->code, |
|
52 | 3 | 'name' => $this->name, |
|
53 | 3 | 'methods' => array_map(static fn (MethodCollection $methods) => $methods->__toArray(), $this->methods), |
|
54 | 3 | ]; |
|
55 | } |
||
56 | } |
||
57 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: