validateItemForArrayConstraintsFromSetItem()   B
last analyzed

Complexity

Conditions 7
Paths 8

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 9
nc 8
nop 1
dl 0
loc 15
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Ovh\ArrayType;
4
5
use \WsdlToPhp\PackageBase\AbstractStructArrayBase;
6
7
/**
8
 * This class stands for MyArrayOfDedicatedIpLoadBalancingServerStructType
9
 * ArrayType
10
 * @subpackage Arrays
11
 * @author WsdlToPhp <[email protected]>
12
 */
13
class MyArrayOfDedicatedIpLoadBalancingServerStructType extends AbstractStructArrayBase
14
{
15
    /**
16
     * The item
17
     * Meta information extracted from the WSDL
18
     * - maxOccurs: unbounded
19
     * - minOccurs: 0
20
     * @var \Ovh\StructType\DedicatedIpLoadBalancingServerStruct[]
21
     */
22
    public $item;
23
    /**
24
     * Constructor method for MyArrayOfDedicatedIpLoadBalancingServerStructType
25
     * @uses MyArrayOfDedicatedIpLoadBalancingServerStructType::setItem()
26
     * @param \Ovh\StructType\DedicatedIpLoadBalancingServerStruct[] $item
27
     */
28
    public function __construct(array $item = array())
29
    {
30
        $this
31
            ->setItem($item);
32
    }
33
    /**
34
     * Get item value
35
     * @return \Ovh\StructType\DedicatedIpLoadBalancingServerStruct[]|null
36
     */
37
    public function getItem()
38
    {
39
        return $this->item;
40
    }
41
    /**
42
     * This method is responsible for validating the values passed to the setItem method
43
     * This method is willingly generated in order to preserve the one-line inline validation within the setItem method
44
     * @param array $values
45
     * @return string A non-empty message if the values does not match the validation rules
46
     */
47
    public static function validateItemForArrayConstraintsFromSetItem(array $values = array())
48
    {
49
        $message = '';
50
        $invalidValues = [];
51
        foreach ($values as $myArrayOfDedicatedIpLoadBalancingServerStructTypeItemItem) {
52
            // validation for constraint: itemType
53
            if (!$myArrayOfDedicatedIpLoadBalancingServerStructTypeItemItem instanceof \Ovh\StructType\DedicatedIpLoadBalancingServerStruct) {
54
                $invalidValues[] = is_object($myArrayOfDedicatedIpLoadBalancingServerStructTypeItemItem) ? get_class($myArrayOfDedicatedIpLoadBalancingServerStructTypeItemItem) : sprintf('%s(%s)', gettype($myArrayOfDedicatedIpLoadBalancingServerStructTypeItemItem), var_export($myArrayOfDedicatedIpLoadBalancingServerStructTypeItemItem, true));
55
            }
56
        }
57
        if (!empty($invalidValues)) {
58
            $message = sprintf('The item property can only contain items of type \Ovh\StructType\DedicatedIpLoadBalancingServerStruct, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
0 ignored issues
show
introduced by
The condition is_array($invalidValues) is always true.
Loading history...
introduced by
The condition is_object($invalidValues) is always false.
Loading history...
59
        }
60
        unset($invalidValues);
61
        return $message;
62
    }
63
    /**
64
     * Set item value
65
     * @throws \InvalidArgumentException
66
     * @param \Ovh\StructType\DedicatedIpLoadBalancingServerStruct[] $item
67
     * @return \Ovh\ArrayType\MyArrayOfDedicatedIpLoadBalancingServerStructType
68
     */
69
    public function setItem(array $item = array())
70
    {
71
        // validation for constraint: array
72
        if ('' !== ($itemArrayErrorMessage = self::validateItemForArrayConstraintsFromSetItem($item))) {
73
            throw new \InvalidArgumentException($itemArrayErrorMessage, __LINE__);
74
        }
75
        $this->item = $item;
76
        return $this;
77
    }
78
    /**
79
     * Add item to item value
80
     * @throws \InvalidArgumentException
81
     * @param \Ovh\StructType\DedicatedIpLoadBalancingServerStruct $item
82
     * @return \Ovh\ArrayType\MyArrayOfDedicatedIpLoadBalancingServerStructType
83
     */
84
    public function addToItem(\Ovh\StructType\DedicatedIpLoadBalancingServerStruct $item)
85
    {
86
        // validation for constraint: itemType
87
        if (!$item instanceof \Ovh\StructType\DedicatedIpLoadBalancingServerStruct) {
0 ignored issues
show
introduced by
$item is always a sub-type of Ovh\StructType\Dedicated...adBalancingServerStruct.
Loading history...
88
            throw new \InvalidArgumentException(sprintf('The item property can only contain items of type \Ovh\StructType\DedicatedIpLoadBalancingServerStruct, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
89
        }
90
        $this->item[] = $item;
91
        return $this;
92
    }
93
    /**
94
     * Returns the current element
95
     * @see AbstractStructArrayBase::current()
96
     * @return \Ovh\StructType\DedicatedIpLoadBalancingServerStruct|null
97
     */
98
    public function current()
99
    {
100
        return parent::current();
101
    }
102
    /**
103
     * Returns the indexed element
104
     * @see AbstractStructArrayBase::item()
105
     * @param int $index
106
     * @return \Ovh\StructType\DedicatedIpLoadBalancingServerStruct|null
107
     */
108
    public function item($index)
109
    {
110
        return parent::item($index);
111
    }
112
    /**
113
     * Returns the first element
114
     * @see AbstractStructArrayBase::first()
115
     * @return \Ovh\StructType\DedicatedIpLoadBalancingServerStruct|null
116
     */
117
    public function first()
118
    {
119
        return parent::first();
120
    }
121
    /**
122
     * Returns the last element
123
     * @see AbstractStructArrayBase::last()
124
     * @return \Ovh\StructType\DedicatedIpLoadBalancingServerStruct|null
125
     */
126
    public function last()
127
    {
128
        return parent::last();
129
    }
130
    /**
131
     * Returns the element at the offset
132
     * @see AbstractStructArrayBase::offsetGet()
133
     * @param int $offset
134
     * @return \Ovh\StructType\DedicatedIpLoadBalancingServerStruct|null
135
     */
136
    public function offsetGet($offset)
137
    {
138
        return parent::offsetGet($offset);
139
    }
140
    /**
141
     * Returns the attribute name
142
     * @see AbstractStructArrayBase::getAttributeName()
143
     * @return string item
144
     */
145
    public function getAttributeName()
146
    {
147
        return 'item';
148
    }
149
}
150