Completed
Push — feature/issue-84 ( 44128e...1e0a90 )
by Mikaël
34:57
created

Struct::addUnionStruct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\Container\Model;
4
5
use WsdlToPhp\PackageGenerator\Generator\Generator;
6
use WsdlToPhp\PackageGenerator\Model\Struct as Model;
7
8
class Struct extends AbstractModel
9
{
10
    /**
11
     * @see \WsdlToPhp\PackageGenerator\Container\Model\Model::objectClass()
12
     * @return string
13
     */
14 456
    protected function objectClass()
15
    {
16 456
        return 'WsdlToPhp\\PackageGenerator\\Model\\Struct';
17
    }
18
    /**
19
     * @param string $name
20
     * @return Model|null
21
     */
22 464
    public function getStructByName($name)
23
    {
24 464
        return $this->get($name);
25
    }
26
    /**
27
     * Adds a virtual struct
28
     * @param string $structName the original struct name
29
     * @return Struct
30
     */
31
    public function addVirtualStruct($structName)
32 448
    {
33
        return $this->addStruct($structName, false);
34 448
    }
35
    /**
36
     * Adds type to structs
37
     * @param string $structName the original struct name
38
     * @param bool $isStruct whether the Struct has to be generated or not
39
     * @return Struct
40
     */
41
    public function addStruct($structName, $isStruct = true)
42
    {
43 456
        if ($this->get($structName) === null) {
44
            $this->add(new Model($this->generator, $structName, $isStruct));
45 456
        }
46 444
        return $this;
47 444
    }
48 456
    /**
49
     * Adds type to structs and its attribute
50
     * @param string $structName the original struct name
51
     * @param string $attributeName the attribute name
52
     * @param string $attributeType the attribute type
53
     * @return Struct
54
     */
55
    public function addStructWithAttribute($structName, $attributeName, $attributeType)
56
    {
57
        $this->addStruct($structName);
58 452
        if (($struct = $this->getStructByName($structName)) instanceof Model) {
59
            $struct->addAttribute($attributeName, $attributeType);
60 452
        }
61 452
        return $this;
62 452
    }
63 452
    /**
64 452
     * Adds a union struct
65
     * @param string $structName
66
     * @param string[] $types
67
     * @return Struct
68
     */
69
    public function addUnionStruct($structName, $types)
70
    {
71 464
        $this->addVirtualStruct($structName);
72
        if (($struct = $this->getStructByName($structName)) instanceof Model) {
73 464
            $struct->setTypes($types);
74
        }
75
        return $this;
76
    }
77
    /**
78
     * @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::get()
79
     * @param string $value
80
     * @return Model|null
81
     */
82
    public function get($value)
83
    {
84
        return parent::get($value);
85
    }
86
}
87