getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
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
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
25
class SoapExceptionEventSubscriber implements EventSubscriberInterface
26
{
27
    /**
28
     * {@inheritDoc}
29
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
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
Coding Style introduced by
Missing short description in doc comment
Loading history...
42
     * @param PreDeserializeEvent $event
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
43
     * @throws Exception
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
44
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
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
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
58 7
            case 6: throw new NotFoundException('No reports from before 1 May 2010 are available');
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
59 6
            case 3: throw new ResponseException('To many results');
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
60 5
            case 5: throw new ResponseException('Synchronisation will probably fail due to expired history-file');
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
61 4
            case 4: throw new RequestException('Incorrect input');
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
62 3
            case 7: throw new RequestException('The maximum interval between datetimeFrom and datetimeTo is one month');
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
63 2
            default: throw new UnavailableException('Technical error while handling the request'); // includes 2
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
64
        }
65
    }
66
}
67