1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace DMT\Insolvency\Soap\Serializer; |
||
4 | |||
5 | use DMT\Insolvency\Exception\Exception; |
||
6 | use DMT\Insolvency\Exception\RequestException; |
||
7 | use DMT\Insolvency\Exception\NotFoundException; |
||
8 | use DMT\Insolvency\Exception\ResponseException; |
||
9 | use DMT\Insolvency\Exception\UnavailableException; |
||
10 | use DMT\Insolvency\Soap\Response; |
||
11 | use JMS\Serializer\EventDispatcher\EventSubscriberInterface; |
||
12 | use JMS\Serializer\EventDispatcher\PreDeserializeEvent; |
||
13 | |||
14 | /** |
||
15 | * Class SoapExceptionEventSubscriber |
||
16 | * |
||
17 | * 1. No results found |
||
18 | * 2. Technical error while handling the request |
||
19 | * 3. To many results |
||
20 | * 4. Incorrect input |
||
21 | * 5. It can not be garantueed that the requested records fit correctly for synchronization purposes |
||
22 | * 6. No reports from before 1 May 2010 are available |
||
23 | * 7. The maximum interval between datetimeFrom and datetimeTo is one month |
||
24 | */ |
||
0 ignored issues
–
show
|
|||
25 | class SoapExceptionEventSubscriber implements EventSubscriberInterface |
||
26 | { |
||
27 | /** |
||
28 | * {@inheritDoc} |
||
29 | */ |
||
0 ignored issues
–
show
|
|||
30 | 12 | public static function getSubscribedEvents() |
|
31 | { |
||
32 | return [ |
||
33 | [ |
||
34 | 12 | 'event' => 'serializer.pre_deserialize', |
|
35 | 'method' => 'toException', |
||
36 | 'format' => 'soap', |
||
37 | ] |
||
38 | ]; |
||
39 | } |
||
40 | |||
41 | /** |
||
0 ignored issues
–
show
|
|||
42 | * @param PreDeserializeEvent $event |
||
0 ignored issues
–
show
|
|||
43 | * @throws Exception |
||
0 ignored issues
–
show
|
|||
44 | */ |
||
0 ignored issues
–
show
|
|||
45 | 19 | public function toException(PreDeserializeEvent $event) |
|
46 | { |
||
47 | 19 | if (!is_a($event->getType()['name'], Response::class, true)) { |
|
48 | 11 | return; |
|
49 | } |
||
50 | |||
51 | 19 | $elements = $event->getData()->xpath('//*[local-name()="exceptie"]/@errorcode'); |
|
52 | 19 | if (!count($elements)) { |
|
53 | 11 | return; |
|
54 | } |
||
55 | |||
56 | 8 | switch ($elements[0]) { |
|
57 | 8 | case 1: throw new NotFoundException('No results found'); |
|
0 ignored issues
–
show
|
|||
58 | 7 | case 6: throw new NotFoundException('No reports from before 1 May 2010 are available'); |
|
0 ignored issues
–
show
|
|||
59 | 6 | case 3: throw new ResponseException('To many results'); |
|
0 ignored issues
–
show
|
|||
60 | 5 | case 5: throw new ResponseException('Synchronisation will probably fail due to expired history-file'); |
|
0 ignored issues
–
show
|
|||
61 | 4 | case 4: throw new RequestException('Incorrect input'); |
|
0 ignored issues
–
show
|
|||
62 | 3 | case 7: throw new RequestException('The maximum interval between datetimeFrom and datetimeTo is one month'); |
|
0 ignored issues
–
show
|
|||
63 | 2 | default: throw new UnavailableException('Technical error while handling the request'); // includes 2 |
|
0 ignored issues
–
show
|
|||
64 | } |
||
65 | } |
||
66 | } |
||
67 |