-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTaricCodeIterator.php
More file actions
46 lines (38 loc) · 1002 Bytes
/
TaricCodeIterator.php
File metadata and controls
46 lines (38 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types=1);
namespace MpApiClient\TaricCode\Entity;
use MpApiClient\Common\Util\AbstractStringKeyIterator;
/**
* @extends AbstractStringKeyIterator<TaricCode>
* @property array<string, TaricCode> $data
*/
final class TaricCodeIterator extends AbstractStringKeyIterator
{
private function __construct(TaricCode ...$data)
{
foreach ($data as $taricCode) {
$this->data[$taricCode->getId()] = $taricCode;
}
}
/**
* @param array<int, array<string, mixed>> $data
*
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
...array_map(fn(array $item): TaricCode => TaricCode::createFromApi($item), $data)
);
}
/**
* @return false|TaricCode
*/
public function current()
{
return current($this->data);
}
public function get(string $key): ?TaricCode
{
return $this->data[$key] ?? null;
}
}