BulkReportResponseDecoder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 23
rs 10
c 1
b 0
f 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A decode() 0 18 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GusApi\Util;
6
7
use GusApi\Exception\InvalidServerResponseException;
8
use GusApi\Type\Response\GetBulkReportResponseRaw;
9
use SimpleXMLElement;
10
11
class BulkReportResponseDecoder
12
{
13
    /**
14
     * @throws InvalidServerResponseException
15
     */
16
    public static function decode(GetBulkReportResponseRaw $bulkReportResponseRaw): array
17
    {
18
        $regons = [];
19
20
        if ('' === $bulkReportResponseRaw->getDanePobierzRaportZbiorczyResult()) {
21
            return $regons;
22
        }
23
24
        try {
25
            $xmlElementsResponse = new SimpleXMLElement($bulkReportResponseRaw->getDanePobierzRaportZbiorczyResult());
26
27
            foreach ($xmlElementsResponse->dane as $regon) {
28
                $regons[] = (string) $regon->regon;
29
            }
30
31
            return $regons;
32
        } catch (\Exception $e) {
33
            throw new InvalidServerResponseException('Invalid server response', 0, $e);
34
        }
35
    }
36
}
37