This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Nip\Utility; |
||
4 | |||
5 | /** |
||
6 | * Class Str |
||
7 | * @package Nip\Utility |
||
8 | */ |
||
9 | class Str |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * The cache of snake-cased words. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected static $snakeCache = []; |
||
18 | /** |
||
19 | * The cache of camel-cased words. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected static $camelCache = []; |
||
24 | /** |
||
25 | * The cache of studly-cased words. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected static $studlyCache = []; |
||
30 | |||
31 | /** |
||
32 | * Convert a value to camel case. |
||
33 | * |
||
34 | * @param string $value |
||
35 | * @return string |
||
36 | */ |
||
37 | public static function camel($value) |
||
38 | { |
||
39 | if (isset(static::$camelCache[$value])) { |
||
40 | return static::$camelCache[$value]; |
||
41 | } |
||
42 | return static::$camelCache[$value] = lcfirst(static::studly($value)); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Convert a value to studly caps case. |
||
47 | * |
||
48 | * @param string $value |
||
49 | * @return string |
||
50 | */ |
||
51 | public static function studly($value) |
||
52 | { |
||
53 | $key = $value; |
||
54 | if (isset(static::$studlyCache[$key])) { |
||
55 | return static::$studlyCache[$key]; |
||
56 | } |
||
57 | $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
||
58 | return static::$studlyCache[$key] = str_replace(' ', '', $value); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Determine if a given string ends with a given substring. |
||
63 | * |
||
64 | * @param string $haystack |
||
65 | * @param string|array $needles |
||
66 | * @return bool |
||
67 | */ |
||
68 | View Code Duplication | public static function endsWith($haystack, $needles) |
|
0 ignored issues
–
show
|
|||
69 | { |
||
70 | foreach ((array)$needles as $needle) { |
||
71 | if (substr($haystack, -strlen($needle)) === (string)$needle) { |
||
72 | return true; |
||
73 | } |
||
74 | } |
||
75 | return false; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Cap a string with a single instance of a given value. |
||
80 | * |
||
81 | * @param string $value |
||
82 | * @param string $cap |
||
83 | * @return string |
||
84 | */ |
||
85 | public static function finish($value, $cap) |
||
86 | { |
||
87 | $quoted = preg_quote($cap, '/'); |
||
88 | return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Determine if a given string matches a given pattern. |
||
93 | * |
||
94 | * @param string $pattern |
||
95 | * @param string $value |
||
96 | * @return bool |
||
97 | */ |
||
98 | public static function is($pattern, $value) |
||
99 | { |
||
100 | if ($pattern == $value) { |
||
101 | return true; |
||
102 | } |
||
103 | $pattern = preg_quote($pattern, '#'); |
||
104 | // Asterisks are translated into zero-or-more regular expression wildcards |
||
105 | // to make it convenient to check if the strings starts with the given |
||
106 | // pattern such as "library/*", making any string check convenient. |
||
107 | $pattern = str_replace('\*', '.*', $pattern); |
||
108 | return (bool)preg_match('#^' . $pattern . '\z#u', $value); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Convert a string to kebab case. |
||
113 | * |
||
114 | * @param string $value |
||
115 | * @return string |
||
116 | */ |
||
117 | public static function kebab($value) |
||
118 | { |
||
119 | return static::snake($value, '-'); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Convert a string to snake case. |
||
124 | * |
||
125 | * @param string $value |
||
126 | * @param string $delimiter |
||
127 | * @return string |
||
128 | */ |
||
129 | public static function snake($value, $delimiter = '_') |
||
130 | { |
||
131 | $key = $value; |
||
132 | if (isset(static::$snakeCache[$key][$delimiter])) { |
||
133 | return static::$snakeCache[$key][$delimiter]; |
||
134 | } |
||
135 | if (!ctype_lower($value)) { |
||
136 | $value = preg_replace('/\s+/u', '', $value); |
||
137 | $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); |
||
138 | } |
||
139 | return static::$snakeCache[$key][$delimiter] = $value; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Convert the given string to lower-case. |
||
144 | * |
||
145 | * @param string $value |
||
146 | * @return string |
||
147 | */ |
||
148 | public static function lower($value) |
||
149 | { |
||
150 | return mb_strtolower($value, 'UTF-8'); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Limit the number of characters in a string. |
||
155 | * |
||
156 | * @param string $value |
||
157 | * @param int $limit |
||
158 | * @param string $end |
||
159 | * @return string |
||
160 | */ |
||
161 | public static function limit($value, $limit = 100, $end = '...') |
||
162 | { |
||
163 | if (mb_strwidth($value, 'UTF-8') <= $limit) { |
||
164 | return $value; |
||
165 | } |
||
166 | return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Limit the number of words in a string. |
||
171 | * |
||
172 | * @param string $value |
||
173 | * @param int $words |
||
174 | * @param string $end |
||
175 | * @return string |
||
176 | */ |
||
177 | public static function words($value, $words = 100, $end = '...') |
||
178 | { |
||
179 | preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $value, $matches); |
||
180 | if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
||
181 | return $value; |
||
182 | } |
||
183 | return rtrim($matches[0]) . $end; |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Return the length of the given string. |
||
188 | * |
||
189 | * @param string $value |
||
190 | * @return int |
||
191 | */ |
||
192 | public static function length($value) |
||
193 | { |
||
194 | return mb_strlen($value); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Parse a Class@method style callback into class and method. |
||
199 | * |
||
200 | * @param string $callback |
||
201 | * @param string|null $default |
||
202 | * @return array |
||
203 | */ |
||
204 | public static function parseCallback($callback, $default = null) |
||
205 | { |
||
206 | return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Determine if a given string contains a given substring. |
||
211 | * |
||
212 | * @param string $haystack |
||
213 | * @param string|array $needles |
||
214 | * @return bool |
||
215 | */ |
||
216 | View Code Duplication | public static function contains($haystack, $needles) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
217 | { |
||
218 | foreach ((array)$needles as $needle) { |
||
219 | if ($needle != '' && mb_strpos($haystack, $needle) !== false) { |
||
220 | return true; |
||
221 | } |
||
222 | } |
||
223 | return false; |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * Get the plural form of an English word. |
||
228 | * |
||
229 | * @param string $value |
||
230 | * @param int $count |
||
231 | * @return string |
||
232 | */ |
||
233 | public static function plural($value, $count = 2) |
||
234 | { |
||
235 | return Pluralizer::plural($value, $count); |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Generate a more truly "random" alpha-numeric string. |
||
240 | * |
||
241 | * @param int $length |
||
242 | * @return string |
||
243 | */ |
||
244 | public static function random($length = 16) |
||
245 | { |
||
246 | $string = ''; |
||
247 | while (($len = strlen($string)) < $length) { |
||
248 | $size = $length - $len; |
||
249 | $bytes = random_bytes($size); |
||
250 | $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
||
251 | } |
||
252 | return $string; |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * Replace a given value in the string sequentially with an array. |
||
257 | * |
||
258 | * @param string $search |
||
259 | * @param array $replace |
||
260 | * @param string $subject |
||
261 | * @return string |
||
262 | */ |
||
263 | public static function replaceArray($search, array $replace, $subject) |
||
264 | { |
||
265 | foreach ($replace as $value) { |
||
266 | $subject = static::replaceFirst($search, $value, $subject); |
||
267 | } |
||
268 | return $subject; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * Replace the first occurrence of a given value in the string. |
||
273 | * |
||
274 | * @param string $search |
||
275 | * @param string $replace |
||
276 | * @param string $subject |
||
277 | * @return string |
||
278 | */ |
||
279 | View Code Duplication | public static function replaceFirst($search, $replace, $subject) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
280 | { |
||
281 | $position = strpos($subject, $search); |
||
282 | if ($position !== false) { |
||
283 | return substr_replace($subject, $replace, $position, strlen($search)); |
||
284 | } |
||
285 | return $subject; |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * Replace the last occurrence of a given value in the string. |
||
290 | * |
||
291 | * @param string $search |
||
292 | * @param string $replace |
||
293 | * @param string $subject |
||
294 | * @return string |
||
295 | */ |
||
296 | View Code Duplication | public static function replaceLast($search, $replace, $subject) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
297 | { |
||
298 | $position = strrpos($subject, $search); |
||
299 | if ($position !== false) { |
||
300 | return substr_replace($subject, $replace, $position, strlen($search)); |
||
301 | } |
||
302 | return $subject; |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * Convert the given string to title case. |
||
307 | * |
||
308 | * @param string $value |
||
309 | * @return string |
||
310 | */ |
||
311 | public static function title($value) |
||
312 | { |
||
313 | return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * Get the singular form of an English word. |
||
318 | * |
||
319 | * @param string $value |
||
320 | * @return string |
||
321 | */ |
||
322 | public static function singular($value) |
||
323 | { |
||
324 | return Pluralizer::singular($value); |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * Generate a URL friendly "slug" from a given string. |
||
329 | * |
||
330 | * @param string $title |
||
331 | * @param string $separator |
||
332 | * @return string |
||
333 | */ |
||
334 | public static function slug($title, $separator = '-') |
||
335 | { |
||
336 | $title = static::ascii($title); |
||
337 | // Convert all dashes/underscores into separator |
||
338 | $flip = $separator == '-' ? '_' : '-'; |
||
339 | $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); |
||
340 | // Remove all characters that are not the separator, letters, numbers, or whitespace. |
||
341 | $title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', mb_strtolower($title)); |
||
342 | // Replace all separator characters and whitespace by a single separator |
||
343 | $title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title); |
||
344 | return trim($title, $separator); |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * Transliterate a UTF-8 value to ASCII. |
||
349 | * |
||
350 | * @param string $value |
||
351 | * @return string |
||
352 | */ |
||
353 | public static function ascii($value) |
||
354 | { |
||
355 | foreach (static::charsArray() as $key => $val) { |
||
356 | $value = str_replace($val, $key, $value); |
||
357 | } |
||
358 | return preg_replace('/[^\x20-\x7E]/u', '', $value); |
||
359 | } |
||
360 | |||
361 | /** |
||
362 | * Returns the replacements for the ascii method. |
||
363 | * |
||
364 | * Note: Adapted from Stringy\Stringy. |
||
365 | * |
||
366 | * @see https://github.com/danielstjules/Stringy/blob/2.3.1/LICENSE.txt |
||
367 | * |
||
368 | * @return array |
||
369 | */ |
||
370 | protected static function charsArray() |
||
371 | { |
||
372 | static $charsArray; |
||
373 | if (isset($charsArray)) { |
||
374 | return $charsArray; |
||
375 | } |
||
376 | return $charsArray = [ |
||
377 | '0' => ['°', '₀', '۰'], |
||
378 | '1' => ['¹', '₁', '۱'], |
||
379 | '2' => ['²', '₂', '۲'], |
||
380 | '3' => ['³', '₃', '۳'], |
||
381 | '4' => ['⁴', '₄', '۴', '٤'], |
||
382 | '5' => ['⁵', '₅', '۵', '٥'], |
||
383 | '6' => ['⁶', '₆', '۶', '٦'], |
||
384 | '7' => ['⁷', '₇', '۷'], |
||
385 | '8' => ['⁸', '₈', '۸'], |
||
386 | '9' => ['⁹', '₉', '۹'], |
||
387 | 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'], |
||
388 | 'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], |
||
389 | 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'], |
||
390 | 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], |
||
391 | 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'], |
||
392 | 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'], |
||
393 | 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], |
||
394 | 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], |
||
395 | 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ'], |
||
396 | 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], |
||
397 | 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], |
||
398 | 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], |
||
399 | 'm' => ['м', 'μ', 'م', 'မ', 'მ'], |
||
400 | 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], |
||
401 | 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'], |
||
402 | 'p' => ['п', 'π', 'ပ', 'პ', 'پ'], |
||
403 | 'q' => ['ყ'], |
||
404 | 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], |
||
405 | 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], |
||
406 | 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], |
||
407 | 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'], |
||
408 | 'v' => ['в', 'ვ', 'ϐ'], |
||
409 | 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], |
||
410 | 'x' => ['χ', 'ξ'], |
||
411 | 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], |
||
412 | 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], |
||
413 | 'aa' => ['ع', 'आ', 'آ'], |
||
414 | 'ae' => ['ä', 'æ', 'ǽ'], |
||
415 | 'ai' => ['ऐ'], |
||
416 | 'at' => ['@'], |
||
417 | 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], |
||
418 | 'dj' => ['ђ', 'đ'], |
||
419 | 'dz' => ['џ', 'ძ'], |
||
420 | 'ei' => ['ऍ'], |
||
421 | 'gh' => ['غ', 'ღ'], |
||
422 | 'ii' => ['ई'], |
||
423 | 'ij' => ['ij'], |
||
424 | 'kh' => ['х', 'خ', 'ხ'], |
||
425 | 'lj' => ['љ'], |
||
426 | 'nj' => ['њ'], |
||
427 | 'oe' => ['ö', 'œ', 'ؤ'], |
||
428 | 'oi' => ['ऑ'], |
||
429 | 'oii' => ['ऒ'], |
||
430 | 'ps' => ['ψ'], |
||
431 | 'sh' => ['ш', 'შ', 'ش'], |
||
432 | 'shch' => ['щ'], |
||
433 | 'ss' => ['ß'], |
||
434 | 'sx' => ['ŝ'], |
||
435 | 'th' => ['þ', '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 'X' => ['Χ', 'Ξ'], |
||
465 | 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'], |
||
466 | 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'], |
||
467 | 'AE' => ['Ä', 'Æ', 'Ǽ'], |
||
468 | 'CH' => ['Ч'], |
||
469 | 'DJ' => ['Ђ'], |
||
470 | 'DZ' => ['Џ'], |
||
471 | 'GX' => ['Ĝ'], |
||
472 | 'HX' => ['Ĥ'], |
||
473 | 'IJ' => ['IJ'], |
||
474 | 'JX' => ['Ĵ'], |
||
475 | 'KH' => ['Х'], |
||
476 | 'LJ' => ['Љ'], |
||
477 | 'NJ' => ['Њ'], |
||
478 | 'OE' => ['Ö', 'Œ'], |
||
479 | 'PS' => ['Ψ'], |
||
480 | 'SH' => ['Ш'], |
||
481 | 'SHCH' => ['Щ'], |
||
482 | 'SS' => ['ẞ'], |
||
483 | 'TH' => ['Þ'], |
||
484 | 'TS' => ['Ц'], |
||
485 | 'UE' => ['Ü'], |
||
486 | 'YA' => ['Я'], |
||
487 | 'YU' => ['Ю'], |
||
488 | 'ZH' => ['Ж'], |
||
489 | ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"], |
||
490 | ]; |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * Determine if a given string starts with a given substring. |
||
495 | * |
||
496 | * @param string $haystack |
||
497 | * @param string|array $needles |
||
498 | * @return bool |
||
499 | */ |
||
500 | View Code Duplication | public static function startsWith($haystack, $needles) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
501 | { |
||
502 | foreach ((array)$needles as $needle) { |
||
503 | if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string)$needle) { |
||
504 | return true; |
||
505 | } |
||
506 | } |
||
507 | return false; |
||
508 | } |
||
509 | |||
510 | /** |
||
511 | * Make a string's first character uppercase. |
||
512 | * |
||
513 | * @param string $string |
||
514 | * @return string |
||
515 | */ |
||
516 | public static function ucfirst($string) |
||
517 | { |
||
518 | return static::upper(static::substr($string, 0, 1)) . static::substr($string, 1); |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * Convert the given string to upper-case. |
||
523 | * |
||
524 | * @param string $value |
||
525 | * @return string |
||
526 | */ |
||
527 | public static function upper($value) |
||
528 | { |
||
529 | return mb_strtoupper($value, 'UTF-8'); |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * Returns the portion of string specified by the start and length parameters. |
||
534 | * |
||
535 | * @param string $string |
||
536 | * @param int $start |
||
537 | * @param int|null $length |
||
538 | * @return string |
||
539 | */ |
||
540 | public static function substr($string, $start, $length = null) |
||
541 | { |
||
542 | return mb_substr($string, $start, $length, 'UTF-8'); |
||
543 | } |
||
544 | } |
||
545 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.