1 | <?php |
||
15 | class Map implements Contract\Struct\Map, Contract\Data\ValueObject { |
||
16 | use Mixin\StructureOfElementsMethods; |
||
17 | use Mixin\CountableMethods; |
||
18 | use Mixin\IteratorMethods; |
||
19 | use Mixin\JsonSerializableMethods; |
||
20 | use Properties; |
||
21 | protected const INVALID_KEY_ERROR_MESSAGE = 'Map support only `string` keys.'; |
||
22 | |||
23 | public function __construct($elements = []) { |
||
31 | |||
32 | /** |
||
33 | * Named constructor. |
||
34 | * |
||
35 | * @param array|iterable $elements elements of collection. |
||
36 | * |
||
37 | * @return Map new map of specified elements. |
||
38 | * |
||
39 | * @since 1.0 |
||
40 | */ |
||
41 | public static function of($elements): Contract\Struct\Map { |
||
44 | |||
45 | public function add(string $key, $element): void { |
||
48 | |||
49 | public function get(string $key) { |
||
52 | |||
53 | public function keysToLowerCase(): void { |
||
56 | |||
57 | public function keysToUpperCase(): void { |
||
60 | |||
61 | /** |
||
62 | * Split collection into chunks of specified size. |
||
63 | * |
||
64 | * @param int $size size of each chunk. |
||
65 | * |
||
66 | * @return Collection a multidimensional numerically indexed collection, starting with zero, |
||
67 | * with each dimension containing Map of specified size. |
||
68 | * |
||
69 | * @since 1.0 |
||
70 | */ |
||
71 | public function chunkBy(int $size): Contract\Struct\Collection { |
||
80 | |||
81 | public function getKeys(): Contract\Struct\Collection { |
||
84 | |||
85 | public function getValues(): Contract\Struct\Collection { |
||
88 | |||
89 | // region ----------------- ARRAY ACCESS METHODS ----------------- |
||
90 | |||
91 | /** |
||
92 | * Whether a offset exists |
||
93 | * |
||
94 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
95 | * |
||
96 | * @param mixed $offset <p> |
||
97 | * An offset to check for. |
||
98 | * </p> |
||
99 | * |
||
100 | * @return boolean true on success or false on failure. |
||
101 | * </p> |
||
102 | * <p> |
||
103 | * The return value will be casted to boolean if non-boolean was returned. |
||
104 | * @since 1.0 |
||
105 | */ |
||
106 | public function offsetExists($offset) { |
||
109 | |||
110 | /** |
||
111 | * Offset to retrieve |
||
112 | * |
||
113 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
114 | * |
||
115 | * @param mixed $offset <p> |
||
116 | * The offset to retrieve. |
||
117 | * </p> |
||
118 | * |
||
119 | * @return mixed Can return all value types. |
||
120 | * @since 1.0 |
||
121 | */ |
||
122 | public function offsetGet($offset) { |
||
125 | |||
126 | /** |
||
127 | * Offset to set |
||
128 | * |
||
129 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
130 | * |
||
131 | * @param mixed $offset <p> |
||
132 | * The offset to assign the value to. |
||
133 | * </p> |
||
134 | * @param mixed $value <p> |
||
135 | * The value to set. |
||
136 | * </p> |
||
137 | * |
||
138 | * @return void |
||
139 | * @since 1.0 |
||
140 | */ |
||
141 | public function offsetSet($offset, $value) { |
||
147 | |||
148 | /** |
||
149 | * Offset to unset |
||
150 | * |
||
151 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
152 | * |
||
153 | * @param mixed $offset <p> |
||
154 | * The offset to unset. |
||
155 | * </p> |
||
156 | * |
||
157 | * @return void |
||
158 | * @since 1.0 |
||
159 | */ |
||
160 | public function offsetUnset($offset) { |
||
163 | /// endregion |
||
164 | } |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.