Passed
Push — master ( 09b005...3754d7 )
by Petr
13:20 queued 20s
created

ListStock   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 21
c 1
b 0
f 0
dl 0
loc 46
ccs 22
cts 22
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 10 1
A getXML() 0 26 6
1
<?php
2
/**
3
 * This file is part of riesenia/pohoda package.
4
 *
5
 * Licensed under the MIT License
6
 * (c) RIESENIA.com
7
 */
8
9
declare(strict_types=1);
10
11
namespace Riesenia\Pohoda;
12
13
use Riesenia\Pohoda\Common\OptionsResolver;
14
use Symfony\Component\OptionsResolver\Options;
15
16
class ListStock extends AbstractAgenda
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 1
    public function getXML(): \SimpleXMLElement
22
    {
23 1
        $xml = $this->createXML()->addChild($this->data['namespace'] . ':list' . $this->data['type'], '', $this->namespace(strval($this->data['namespace'])));
24 1
        $xml->addAttribute('version', '2.0');
25
26 1
        if ($this->data['timestamp']) {
27 1
            $date = $this->data['timestamp'];
28 1
            if (is_a($date, \DateTimeInterface::class)) {
29 1
                $date = $date->format('Y-m-d\TH:i:s');
30
            }
31 1
            $xml->addAttribute('dateTimeStamp', $date);
32
        }
33
34 1
        if ($this->data['validFrom']) {
35 1
            $dateFrom = $this->data['validFrom'];
36 1
            if (is_a($dateFrom, \DateTimeInterface::class)) {
37 1
                $dateFrom = $dateFrom->format('Y-m-d');
38
            }
39 1
            $xml->addAttribute('dateValidFrom', $dateFrom);
40
        }
41
42 1
        if ($this->data['state']) {
43 1
            $xml->addAttribute('state', $this->data['state']);
44
        }
45
46 1
        return $xml;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    protected function configureOptions(OptionsResolver $resolver): void
53
    {
54
        // available options
55 1
        $resolver->setDefined(['type', 'namespace', 'timestamp', 'validFrom', 'state']);
56
57
        // validate / format options
58 1
        $resolver->setRequired('type');
59 1
        $resolver->setNormalizer('type', $this->normalizerFactory->getClosure('list_request_type'));
60 1
        $resolver->setDefault('namespace', function (Options $options) {
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

60
        $resolver->setDefault('namespace', function (/** @scrutinizer ignore-unused */ Options $options) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61 1
            return 'lst';
62 1
        });
63
    }
64
}
65