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