XmlForm::toArray()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
cc 5
eloc 12
nc 5
nop 0
1
<?php
2
3
namespace Saxulum\RestCrud\Request\Converter;
4
5
use JMS\Serializer\Annotation as Serializer;
6
7
/**
8
 * @Serializer\XmlRoot("form")
9
 */
10
class XmlForm
11
{
12
    /**
13
     * @var string
14
     * @Serializer\XmlAttribute
15
     * @Serializer\Type("string")
16
     */
17
    protected $name;
18
19
    /**
20
     * @var string
21
     * @Serializer\XmlValue
22
     * @Serializer\Type("string")
23
     */
24
    protected $value;
25
26
    /**
27
     * @var XmlForm[]
28
     * @Serializer\XmlList(inline = true, entry = "form")
29
     * @Serializer\Type("array<Saxulum\RestCrud\Request\Converter\XmlForm>")
30
     */
31
    protected $forms;
32
33
    /**
34
     * @return array
35
     */
36
    public function toArray()
37
    {
38
        if ($this->value) {
39
            if (is_numeric($this->value)) {
40
                if ((int) $this->value == $this->value) {
41
                    $this->value = (int) $this->value;
0 ignored issues
show
Documentation Bug introduced by
The property $value was declared of type string, but (int) $this->value is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
42
                } else {
43
                    $this->value = (float) $this->value;
0 ignored issues
show
Documentation Bug introduced by
The property $value was declared of type string, but (double) $this->value is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
44
                }
45
            }
46
47
            return array($this->name => $this->value);
48
        }
49
50
        $forms = array();
51
        foreach ($this->forms as $form) {
52
            $forms = array_replace($forms, $form->toArray());
53
        }
54
55
        return array($this->name => $forms);
56
    }
57
}
58