1 | <?php |
||
25 | class IndexKey |
||
26 | { |
||
27 | use AccessorTrait; |
||
28 | |||
29 | const UUID_LENGTH = 36; |
||
30 | const ENCODED_ID_LENGTH = 16; |
||
31 | const ENCODED_UUID_LENGTH = 22; |
||
32 | const HASH_LENGTH = Pathname::HASH_LENGTH; |
||
33 | |||
34 | /** |
||
35 | * @var IndexKey[] |
||
36 | */ |
||
37 | static private $instances = []; |
||
38 | |||
39 | /** |
||
40 | * Creates a {@link IndexKey} instance from a composite key string or array. |
||
41 | * |
||
42 | * @param string|array $composite_or_array A composite key string or array. |
||
43 | * |
||
44 | * @return static |
||
45 | */ |
||
46 | static public function from($composite_or_array) |
||
66 | |||
67 | /** |
||
68 | * Parse index key string. |
||
69 | * |
||
70 | * @param string $key |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | static private function parse_key($key) |
||
82 | |||
83 | /** |
||
84 | * Formats a composite key. |
||
85 | * |
||
86 | * @param string $encoded_id |
||
87 | * @param string $encoded_uuid |
||
88 | * @param string $hash |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | static private function format_key($encoded_id, $encoded_uuid, $hash) |
||
96 | |||
97 | /** |
||
98 | * Encodes identifier as a key part. |
||
99 | * |
||
100 | * @param int $id |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | static public function encode_id($id) |
||
108 | |||
109 | /** |
||
110 | * Decodes identifier encoded by {@link self::encode_id()}. |
||
111 | * |
||
112 | * @param string $encoded_id |
||
113 | * |
||
114 | * @return number |
||
115 | */ |
||
116 | static public function decode_id($encoded_id) |
||
120 | |||
121 | /** |
||
122 | * Encodes a UUID as a key part. |
||
123 | * |
||
124 | * @param $uuid |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | static public function encode_uuid($uuid) |
||
137 | |||
138 | /** |
||
139 | * Decodes UUID encoded by {@link self::encode_uuid()}. |
||
140 | * |
||
141 | * @param string $encoded_uuid |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | static public function decode_uuid($encoded_uuid) |
||
152 | |||
153 | /** |
||
154 | * @var int |
||
155 | */ |
||
156 | private $encoded_id; |
||
157 | |||
158 | protected function get_encoded_id() |
||
162 | |||
163 | protected function get_id() |
||
167 | |||
168 | /** |
||
169 | * @var string |
||
170 | */ |
||
171 | private $encoded_uuid; |
||
172 | |||
173 | protected function get_encoded_uuid() |
||
177 | |||
178 | protected function get_uuid() |
||
182 | |||
183 | /** |
||
184 | * @var string |
||
185 | */ |
||
186 | private $hash; |
||
187 | |||
188 | protected function get_hash() |
||
192 | |||
193 | /** |
||
194 | * @param string $encoded_id An encoded identifier as returned by {@link self::encode_id()} |
||
195 | * @param string $encoded_uuid A UUID as encoded by {@link self::encode_uid()} |
||
196 | * @param string $hash A hash as returned by {@link Pathname::hash()} |
||
197 | */ |
||
198 | private function __construct($encoded_id, $encoded_uuid, $hash) |
||
204 | |||
205 | /** |
||
206 | * Returns a formatted composite key. |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | public function __toString() |
||
214 | } |
||
215 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.