1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpCfdi\Finkok\Services\Cancel; |
6
|
|
|
|
7
|
|
|
use ArrayIterator; |
8
|
|
|
use OutOfRangeException; |
9
|
|
|
use PhpCfdi\Finkok\Definitions\CancelAnswer; |
10
|
|
|
use PhpCfdi\Finkok\Services\AbstractCollection; |
11
|
|
|
use stdClass; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @method AcceptRejectUuidItem get(int $index) |
15
|
|
|
* @method AcceptRejectUuidItem first() |
16
|
|
|
* @method ArrayIterator|AcceptRejectUuidItem[] getIterator() |
17
|
|
|
* @extends AbstractCollection<AcceptRejectUuidItem> |
18
|
|
|
*/ |
19
|
|
|
class AcceptRejectUuidList extends AbstractCollection |
20
|
|
|
{ |
21
|
3 |
|
public function findByUuidOrFail(string $uuid): AcceptRejectUuidItem |
22
|
|
|
{ |
23
|
3 |
|
$found = $this->findByUuid($uuid); |
24
|
3 |
|
if (null === $found) { |
25
|
1 |
|
throw new OutOfRangeException(sprintf('UUID %s not found on result', $uuid)); |
26
|
|
|
} |
27
|
2 |
|
return $found; |
28
|
|
|
} |
29
|
|
|
|
30
|
5 |
|
public function findByUuid(string $uuid): ?AcceptRejectUuidItem |
31
|
|
|
{ |
32
|
5 |
|
foreach ($this->getIterator() as $item) { |
33
|
5 |
|
if (0 === strcasecmp($item->uuid(), $uuid)) { |
34
|
3 |
|
return $item; |
35
|
|
|
} |
36
|
|
|
} |
37
|
2 |
|
return null; |
38
|
|
|
} |
39
|
|
|
|
40
|
9 |
|
protected function createItemFromStdClass(stdClass $content): object |
41
|
|
|
{ |
42
|
9 |
|
if (isset($content->{'Acepta'})) { |
43
|
9 |
|
$source = $content->{'Acepta'}; |
44
|
9 |
|
$answer = CancelAnswer::accept(); |
45
|
9 |
|
} elseif (isset($content->{'Rechaza'})) { |
46
|
9 |
|
$source = $content->{'Rechaza'}; |
47
|
9 |
|
$answer = CancelAnswer::reject(); |
48
|
|
|
} else { |
49
|
1 |
|
$source = (object)[]; |
50
|
1 |
|
$answer = CancelAnswer::accept(); |
51
|
|
|
} |
52
|
9 |
|
return new AcceptRejectUuidItem( |
53
|
9 |
|
strval($source->uuid ?? ''), |
54
|
9 |
|
new AcceptRejectUuidStatus($source->status ?? '0'), |
55
|
9 |
|
$answer |
56
|
9 |
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|