ListStock   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
eloc 25
c 2
b 0
f 0
dl 0
loc 54
ccs 26
cts 26
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 18 3
B getXML() 0 26 8
1
<?php
2
3
/**
4
 * This file is part of riesenia/pohoda package.
5
 *
6
 * Licensed under the MIT License
7
 * (c) RIESENIA.com
8
 */
9
10
declare(strict_types=1);
11
12
namespace Riesenia\Pohoda;
13
14
use Riesenia\Pohoda\Common\OptionsResolver;
15
use Symfony\Component\OptionsResolver\Options;
16
17
/**
18
 * @deprecated since 2025-09-15 v3.0.1
19
 * Bad naming, bad context
20
 * @see ListResponse
21
 */
22
class ListStock extends AbstractAgenda
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    public function getXML(): \SimpleXMLElement
28
    {
29 3
        $xml = $this->createXML()->addChild($this->data['namespace'] . ':list' . $this->data['type'], '', $this->namespace(strval($this->data['namespace'])));
30 3
        $xml->addAttribute('version', '2.0');
31
32 3
        if ($this->data['timestamp']) {
33 3
            $date = $this->data['timestamp'];
34 3
            if (is_object($date) && is_a($date, \DateTimeInterface::class)) {
35 3
                $date = $date->format('Y-m-d\TH:i:s');
36
            }
37 3
            $xml->addAttribute('dateTimeStamp', strval($date));
38
        }
39
40 3
        if ($this->data['validFrom']) {
41 3
            $dateFrom = $this->data['validFrom'];
42 3
            if (is_object($dateFrom) && is_a($dateFrom, \DateTimeInterface::class)) {
43 3
                $dateFrom = $dateFrom->format('Y-m-d');
44
            }
45 3
            $xml->addAttribute('dateValidFrom', strval($dateFrom));
46
        }
47
48 3
        if ($this->data['state']) {
49 3
            $xml->addAttribute('state', strval($this->data['state']));
50
        }
51
52 3
        return $xml;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 3
    protected function configureOptions(OptionsResolver $resolver): void
59
    {
60
        // available options
61 1
        $resolver->setDefined(['type', 'namespace', 'timestamp', 'validFrom', 'state']);
62
63
        // validate / format options
64 1
        $resolver->setRequired('type');
65 1
        $resolver->setNormalizer('type', $this->normalizerFactory->getClosure('list_request_type'));
66 1
        $resolver->setDefault('namespace', function (Options $options) {
67 3
            if ('Stock' == $options['type']) {
68 1
                return 'lStk';
69
            }
70
71 2
            if ('AddressBook' == $options['type']) {
72 1
                return 'lAdb';
73
            }
74
75 1
            return 'lst';
76 1
        });
77
    }
78
}
79