Completed
Push — feature/issue-91 ( f0947a )
by Mikaël
02:05
created

Struct::addStruct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
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 690
    protected function objectClass()
15
    {
16 690
        return 'WsdlToPhp\PackageGenerator\Model\Struct';
17
    }
18
    /**
19
     * @param string $name
20
     * @return Model|null
21
     */
22 714
    public function getStructByName($name)
23
    {
24 714
        return $this->get($name);
25
    }
26
    /**
27
     * Adds a virtual struct
28
     * @param string $structName the original struct name
29
     * @return Struct
30
     */
31 690
    public function addVirtualStruct($structName)
32
    {
33 690
        return $this->addStruct($structName, false);
34
    }
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 702
    public function addStruct($structName, $isStruct = true)
42
    {
43 702
        if ($this->get($structName) === null) {
44 672
            $this->add(new Model($this->generator, $structName, $isStruct));
45 672
        }
46 702
        return $this;
47
    }
48
    /**
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 696
    public function addStructWithAttribute($structName, $attributeName, $attributeType)
56
    {
57 696
        $this->addStruct($structName);
58 696
        if (($struct = $this->getStructByName($structName)) instanceof Model) {
59 696
            $struct->addAttribute($attributeName, $attributeType);
60 696
        }
61 696
        return $this;
62
    }
63
    /**
64
     * Adds a union struct
65
     * @param string $structName
66
     * @param string[] $types
67
     * @return Struct
68
     */
69 42
    public function addUnionStruct($structName, $types)
70
    {
71 42
        $this->addVirtualStruct($structName);
72 42
        if (($struct = $this->getStructByName($structName)) instanceof Model) {
73 42
            $struct->setTypes($types);
74 42
        }
75 42
        return $this;
76
    }
77
    /**
78
     * @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::get()
79
     * @param string $value
80
     * @return Model|null
81
     */
82 714
    public function get($value)
83
    {
84 714
        return parent::get($value);
85
    }
86
}
87