1 | <?php |
||
12 | final class Stack implements \IteratorAggregate, \ArrayAccess, Collection |
||
13 | { |
||
14 | use Traits\Collection; |
||
15 | |||
16 | /** |
||
17 | * @var Vector |
||
18 | */ |
||
19 | private $internal; |
||
20 | |||
21 | /** |
||
22 | * Creates an instance using the values of an array or Traversable object. |
||
23 | * |
||
24 | * @param array|\Traversable $values |
||
|
|||
25 | */ |
||
26 | public function __construct($values = null) |
||
27 | { |
||
28 | $this->internal = new Vector($values ?: []); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Clear all elements in the Stack |
||
33 | */ |
||
34 | public function clear() |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | public function copy(): Collection |
||
46 | |||
47 | /** |
||
48 | * Returns the number of elements in the Stack |
||
49 | * |
||
50 | * @return int |
||
51 | */ |
||
52 | public function count(): int |
||
56 | |||
57 | /** |
||
58 | * Ensures that enough memory is allocated for a specified capacity. This |
||
59 | * potentially reduces the number of reallocations as the size increases. |
||
60 | * |
||
61 | * @param int $capacity The number of values for which capacity should be |
||
62 | * allocated. Capacity will stay the same if this value |
||
63 | * is less than or equal to the current capacity. |
||
64 | */ |
||
65 | public function allocate(int $capacity) |
||
69 | |||
70 | /** |
||
71 | * Returns the current capacity of the stack. |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | public function capacity(): int |
||
79 | |||
80 | /** |
||
81 | * Returns the value at the top of the stack without removing it. |
||
82 | * |
||
83 | * @return mixed |
||
84 | * |
||
85 | * @throws UnderflowException if the stack is empty. |
||
86 | */ |
||
87 | public function peek() |
||
91 | |||
92 | /** |
||
93 | * Returns and removes the value at the top of the stack |
||
94 | * |
||
95 | * @return mixed |
||
96 | * |
||
97 | * @throws UnderflowException if the stack is empty. |
||
98 | */ |
||
99 | public function pop() |
||
103 | |||
104 | /** |
||
105 | * Pushes zero or more values onto the top of the stack. |
||
106 | * |
||
107 | * @param mixed ...$values |
||
108 | */ |
||
109 | public function push(...$values) |
||
113 | |||
114 | /** |
||
115 | * @inheritDoc |
||
116 | */ |
||
117 | public function toArray(): array |
||
121 | |||
122 | /** |
||
123 | * Get iterator |
||
124 | */ |
||
125 | public function getIterator() |
||
131 | |||
132 | /** |
||
133 | * @inheritdoc |
||
134 | * |
||
135 | * @throws Error |
||
136 | */ |
||
137 | public function offsetSet($offset, $value) |
||
145 | |||
146 | /** |
||
147 | * @inheritdoc |
||
148 | * |
||
149 | * @throws Error |
||
150 | */ |
||
151 | public function offsetGet($offset) |
||
155 | |||
156 | /** |
||
157 | * @inheritdoc |
||
158 | * |
||
159 | * @throws Error |
||
160 | */ |
||
161 | public function offsetUnset($offset) |
||
165 | |||
166 | /** |
||
167 | * @inheritdoc |
||
168 | * |
||
169 | * @throws Error |
||
170 | */ |
||
171 | public function offsetExists($offset) |
||
175 | } |
||
176 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
array
and suggests a stricter type likearray<String>
.Most often this is a case of a parameter that can be null in addition to its declared types.