@@ -15,8 +15,7 @@ |
||
15 | 15 | { |
16 | 16 | public function __construct() |
17 | 17 | { |
18 | - parent::__construct |
|
19 | - ( |
|
18 | + parent::__construct( |
|
20 | 19 | 'You can not append a string of a different encoding '. |
21 | 20 | 'to that of the existing string!' |
22 | 21 | ); |
@@ -232,16 +232,14 @@ |
||
232 | 232 | */ |
233 | 233 | public function remove($startIndex, $length) |
234 | 234 | { |
235 | - $start = UTF8::substr |
|
236 | - ( |
|
235 | + $start = UTF8::substr( |
|
237 | 236 | (string)$this->str, |
238 | 237 | 0, |
239 | 238 | $startIndex, |
240 | 239 | $this->str->getEncoding() |
241 | 240 | ); |
242 | 241 | |
243 | - $end = UTF8::substr |
|
244 | - ( |
|
242 | + $end = UTF8::substr( |
|
245 | 243 | (string)$this->str, |
246 | 244 | $startIndex + $length, |
247 | 245 | $this->str->getLength(), |
@@ -96,15 +96,13 @@ discard block |
||
96 | 96 | // Make sure we can use the provided string value as a string. |
97 | 97 | if (is_array($string)) |
98 | 98 | { |
99 | - throw new \InvalidArgumentException |
|
100 | - ( |
|
99 | + throw new \InvalidArgumentException( |
|
101 | 100 | 'Passed value cannot be an array' |
102 | 101 | ); |
103 | 102 | } |
104 | 103 | elseif (is_object($string) && !method_exists($string, '__toString')) |
105 | 104 | { |
106 | - throw new \InvalidArgumentException |
|
107 | - ( |
|
105 | + throw new \InvalidArgumentException( |
|
108 | 106 | 'Passed object must have a __toString method' |
109 | 107 | ); |
110 | 108 | } |
@@ -126,7 +124,7 @@ discard block |
||
126 | 124 | } |
127 | 125 | |
128 | 126 | // Set the strings length property. |
129 | - $this->stringLength = UTF8::strlen($this->scalarString,$this->encoding); |
|
127 | + $this->stringLength = UTF8::strlen($this->scalarString, $this->encoding); |
|
130 | 128 | } |
131 | 129 | |
132 | 130 | /** |
@@ -286,8 +284,7 @@ discard block |
||
286 | 284 | throw new \OutOfBoundsException('No character exists at the index'); |
287 | 285 | } |
288 | 286 | |
289 | - return $this->newSelf(UTF8::substr |
|
290 | - ( |
|
287 | + return $this->newSelf(UTF8::substr( |
|
291 | 288 | $this->scalarString, |
292 | 289 | $offset, |
293 | 290 | 1, |
@@ -29,8 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function startsWith($substring, $caseSensitive = true) |
31 | 31 | { |
32 | - $startOfStr = UTF8::substr |
|
33 | - ( |
|
32 | + $startOfStr = UTF8::substr( |
|
34 | 33 | $this->scalarString, |
35 | 34 | 0, |
36 | 35 | UTF8::strlen($substring, $this->encoding), |
@@ -60,8 +59,7 @@ discard block |
||
60 | 59 | { |
61 | 60 | $substringLength = UTF8::strlen($substring, $this->encoding); |
62 | 61 | |
63 | - $endOfStr = UTF8::substr |
|
64 | - ( |
|
62 | + $endOfStr = UTF8::substr( |
|
65 | 63 | $this->scalarString, |
66 | 64 | $this->getLength() - $substringLength, |
67 | 65 | $substringLength, |
@@ -66,16 +66,14 @@ discard block |
||
66 | 66 | { |
67 | 67 | if ($index > $this->getLength()) throw new \OutOfBoundsException(); |
68 | 68 | |
69 | - $start = UTF8::substr |
|
70 | - ( |
|
69 | + $start = UTF8::substr( |
|
71 | 70 | $this->scalarString, |
72 | 71 | 0, |
73 | 72 | $index, |
74 | 73 | $this->encoding |
75 | 74 | ); |
76 | 75 | |
77 | - $end = UTF8::substr |
|
78 | - ( |
|
76 | + $end = UTF8::substr( |
|
79 | 77 | $this->scalarString, |
80 | 78 | $index, |
81 | 79 | $this->getLength(), |
@@ -104,8 +102,7 @@ discard block |
||
104 | 102 | */ |
105 | 103 | public function repeat($multiplier) |
106 | 104 | { |
107 | - return $this->newSelf |
|
108 | - ( |
|
105 | + return $this->newSelf( |
|
109 | 106 | UTF8::str_repeat($this->scalarString, $multiplier) |
110 | 107 | ); |
111 | 108 | } |
@@ -163,8 +160,7 @@ discard block |
||
163 | 160 | $length = $end - $start; |
164 | 161 | } |
165 | 162 | |
166 | - return $this->newSelf |
|
167 | - ( |
|
163 | + return $this->newSelf( |
|
168 | 164 | UTF8::substr($this->scalarString, $start, $length, $this->encoding) |
169 | 165 | ); |
170 | 166 | } |
@@ -179,8 +175,7 @@ discard block |
||
179 | 175 | */ |
180 | 176 | public function surround($substring) |
181 | 177 | { |
182 | - return $this->newSelf |
|
183 | - ( |
|
178 | + return $this->newSelf( |
|
184 | 179 | implode('', [$substring, $this->scalarString, $substring]) |
185 | 180 | ); |
186 | 181 | } |
@@ -213,8 +208,7 @@ discard block |
||
213 | 208 | { |
214 | 209 | if ($caseSensitive) |
215 | 210 | { |
216 | - return UTF8::substr_count |
|
217 | - ( |
|
211 | + return UTF8::substr_count( |
|
218 | 212 | $this->scalarString, |
219 | 213 | $substring, |
220 | 214 | $this->encoding |
@@ -42,8 +42,7 @@ |
||
42 | 42 | $endIndex = $this->indexOf($end, $substrIndex); |
43 | 43 | if ($endIndex === false) return $this->newSelf(''); |
44 | 44 | |
45 | - $result = UTF8::substr |
|
46 | - ( |
|
45 | + $result = UTF8::substr( |
|
47 | 46 | $this->scalarString, |
48 | 47 | $substrIndex, |
49 | 48 | $endIndex - $substrIndex, |
@@ -44,8 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function toLowerCase() |
46 | 46 | { |
47 | - return $this->newSelf |
|
48 | - ( |
|
47 | + return $this->newSelf( |
|
49 | 48 | UTF8::strtolower($this->scalarString, $this->encoding) |
50 | 49 | ); |
51 | 50 | } |
@@ -57,8 +56,7 @@ discard block |
||
57 | 56 | */ |
58 | 57 | public function toUpperCase() |
59 | 58 | { |
60 | - return $this->newSelf |
|
61 | - ( |
|
59 | + return $this->newSelf( |
|
62 | 60 | UTF8::strtoupper($this->scalarString, $this->encoding) |
63 | 61 | ); |
64 | 62 | } |
@@ -74,15 +72,13 @@ discard block |
||
74 | 72 | { |
75 | 73 | if (!class_exists('\\ICanBoogie\\Inflector')) |
76 | 74 | { |
77 | - throw new \RuntimeException |
|
78 | - ( |
|
75 | + throw new \RuntimeException( |
|
79 | 76 | "This method requires ICanBoogie\Inflector. ". |
80 | 77 | "Install with: composer require icanboogie/inflector" |
81 | 78 | ); |
82 | 79 | } |
83 | 80 | |
84 | - return $this->newSelf |
|
85 | - ( |
|
81 | + return $this->newSelf( |
|
86 | 82 | \ICanBoogie\Inflector::get($language) |
87 | 83 | ->singularize($this->scalarString) |
88 | 84 | ); |
@@ -99,15 +95,13 @@ discard block |
||
99 | 95 | { |
100 | 96 | if (!class_exists('\\ICanBoogie\\Inflector')) |
101 | 97 | { |
102 | - throw new \RuntimeException |
|
103 | - ( |
|
98 | + throw new \RuntimeException( |
|
104 | 99 | "This method requires ICanBoogie\Inflector. ". |
105 | 100 | "Install with: composer require icanboogie/inflector" |
106 | 101 | ); |
107 | 102 | } |
108 | 103 | |
109 | - return $this->newSelf |
|
110 | - ( |
|
104 | + return $this->newSelf( |
|
111 | 105 | \ICanBoogie\Inflector::get($language) |
112 | 106 | ->pluralize($this->scalarString) |
113 | 107 | ); |
@@ -123,8 +117,7 @@ discard block |
||
123 | 117 | */ |
124 | 118 | public function toAscii() |
125 | 119 | { |
126 | - return $this->newSelf |
|
127 | - ( |
|
120 | + return $this->newSelf( |
|
128 | 121 | UTF8::toAscii($this->scalarString) |
129 | 122 | ); |
130 | 123 | } |
@@ -184,10 +177,8 @@ discard block |
||
184 | 177 | */ |
185 | 178 | public function toSpaces($tabLength = 4) |
186 | 179 | { |
187 | - return $this->newSelf |
|
188 | - ( |
|
189 | - UTF8::str_replace |
|
190 | - ( |
|
180 | + return $this->newSelf( |
|
181 | + UTF8::str_replace( |
|
191 | 182 | "\t", |
192 | 183 | UTF8::str_repeat(' ', $tabLength), |
193 | 184 | $this->scalarString |
@@ -208,10 +199,8 @@ discard block |
||
208 | 199 | */ |
209 | 200 | public function toTabs($tabLength = 4) |
210 | 201 | { |
211 | - return $this->newSelf |
|
212 | - ( |
|
213 | - UTF8::str_replace |
|
214 | - ( |
|
202 | + return $this->newSelf( |
|
203 | + UTF8::str_replace( |
|
215 | 204 | UTF8::str_repeat(' ', $tabLength), |
216 | 205 | "\t", |
217 | 206 | $this->scalarString |
@@ -263,10 +252,9 @@ discard block |
||
263 | 252 | |
264 | 253 | $camelCase = preg_replace('/^[-_]+/', '', (string)$camelCase); |
265 | 254 | |
266 | - $camelCase = preg_replace_callback |
|
267 | - ( |
|
255 | + $camelCase = preg_replace_callback( |
|
268 | 256 | '/[-_\s]+(.)?/u', |
269 | - function ($match) |
|
257 | + function($match) |
|
270 | 258 | { |
271 | 259 | if (isset($match[1])) |
272 | 260 | { |
@@ -280,10 +268,9 @@ discard block |
||
280 | 268 | $camelCase |
281 | 269 | ); |
282 | 270 | |
283 | - $camelCase = preg_replace_callback |
|
284 | - ( |
|
271 | + $camelCase = preg_replace_callback( |
|
285 | 272 | '/[\d]+(.)?/u', |
286 | - function ($match) |
|
273 | + function($match) |
|
287 | 274 | { |
288 | 275 | return UTF8::strtoupper($match[0], $this->encoding); |
289 | 276 | }, |
@@ -308,31 +295,29 @@ discard block |
||
308 | 295 | |
309 | 296 | $snake = str_replace('-', '_', $snake); |
310 | 297 | |
311 | - $snake = preg_replace_callback |
|
312 | - ( |
|
298 | + $snake = preg_replace_callback( |
|
313 | 299 | '/([\d|A-Z])/u', |
314 | - function ($matches) |
|
300 | + function($matches) |
|
315 | 301 | { |
316 | 302 | $match = $matches[1]; |
317 | 303 | $matchInt = (int)$match; |
318 | 304 | |
319 | 305 | if ("$matchInt" == $match) |
320 | 306 | { |
321 | - return '_' . $match . '_'; |
|
307 | + return '_'.$match.'_'; |
|
322 | 308 | } |
323 | 309 | else |
324 | 310 | { |
325 | - return '_' . UTF8::strtolower($match, $this->encoding); |
|
311 | + return '_'.UTF8::strtolower($match, $this->encoding); |
|
326 | 312 | } |
327 | 313 | }, |
328 | 314 | $snake |
329 | 315 | ); |
330 | 316 | |
331 | - $snake = preg_replace |
|
332 | - ( |
|
317 | + $snake = preg_replace( |
|
333 | 318 | [ |
334 | - '/\s+/', // convert spaces to "_" |
|
335 | - '/^\s+|\s+$/', // trim leading & trailing spaces |
|
319 | + '/\s+/', // convert spaces to "_" |
|
320 | + '/^\s+|\s+$/', // trim leading & trailing spaces |
|
336 | 321 | '/_+/' // remove double "_" |
337 | 322 | ], |
338 | 323 | [ |
@@ -364,10 +349,9 @@ discard block |
||
364 | 349 | */ |
365 | 350 | public function toTitleCase($ignore = null) |
366 | 351 | { |
367 | - return $this->newSelf(preg_replace_callback |
|
368 | - ( |
|
352 | + return $this->newSelf(preg_replace_callback( |
|
369 | 353 | '/([\S]+)/u', |
370 | - function ($match) use ($ignore) |
|
354 | + function($match) use ($ignore) |
|
371 | 355 | { |
372 | 356 | if ($ignore && in_array($match[0], $ignore, true)) |
373 | 357 | { |
@@ -415,17 +399,14 @@ discard block |
||
415 | 399 | { |
416 | 400 | if (!class_exists('\\voku\\helper\\URLify')) |
417 | 401 | { |
418 | - throw new \RuntimeException |
|
419 | - ( |
|
402 | + throw new \RuntimeException( |
|
420 | 403 | "This method requires \voku\helper\URLify. ". |
421 | 404 | "Install with: composer require voku/urlify" |
422 | 405 | ); |
423 | 406 | } |
424 | 407 | |
425 | - return $this->newSelf |
|
426 | - ( |
|
427 | - \voku\helper\URLify::slug |
|
428 | - ( |
|
408 | + return $this->newSelf( |
|
409 | + \voku\helper\URLify::slug( |
|
429 | 410 | $this->scalarString, |
430 | 411 | $language, |
431 | 412 | $replacement, |
@@ -28,8 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | if ($n > 0) |
30 | 30 | { |
31 | - $first = UTF8::substr |
|
32 | - ( |
|
31 | + $first = UTF8::substr( |
|
33 | 32 | $this->scalarString, |
34 | 33 | 0, |
35 | 34 | $n, |
@@ -53,8 +52,7 @@ discard block |
||
53 | 52 | |
54 | 53 | if ($n > 0) |
55 | 54 | { |
56 | - $last = UTF8::substr |
|
57 | - ( |
|
55 | + $last = UTF8::substr( |
|
58 | 56 | $this->scalarString, |
59 | 57 | -$n, |
60 | 58 | null, |
@@ -30,8 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | if ($caseSensitive) |
32 | 32 | { |
33 | - $return = UTF8::str_replace |
|
34 | - ( |
|
33 | + $return = UTF8::str_replace( |
|
35 | 34 | $search, |
36 | 35 | $replacement, |
37 | 36 | $this->scalarString |
@@ -39,8 +38,7 @@ discard block |
||
39 | 38 | } |
40 | 39 | else |
41 | 40 | { |
42 | - $return = UTF8::str_ireplace |
|
43 | - ( |
|
41 | + $return = UTF8::str_ireplace( |
|
44 | 42 | $search, |
45 | 43 | $replacement, |
46 | 44 | $this->scalarString |
@@ -76,8 +74,7 @@ discard block |
||
76 | 74 | |
77 | 75 | if (count($search) !== count($replacement)) |
78 | 76 | { |
79 | - throw new \InvalidArgumentException |
|
80 | - ( |
|
77 | + throw new \InvalidArgumentException( |
|
81 | 78 | '$search and $replacement must the same length!' |
82 | 79 | ); |
83 | 80 | } |
@@ -103,8 +100,7 @@ discard block |
||
103 | 100 | */ |
104 | 101 | public function replaceBeginning($search, $replacement) |
105 | 102 | { |
106 | - return $this->regexReplace |
|
107 | - ( |
|
103 | + return $this->regexReplace( |
|
108 | 104 | '^'.preg_quote($search, '/'), |
109 | 105 | UTF8::str_replace('\\', '\\\\', $replacement) |
110 | 106 | ); |
@@ -120,8 +116,7 @@ discard block |
||
120 | 116 | */ |
121 | 117 | public function replaceEnding($search, $replacement) |
122 | 118 | { |
123 | - return $this->regexReplace |
|
124 | - ( |
|
119 | + return $this->regexReplace( |
|
125 | 120 | preg_quote($search, '/').'$', |
126 | 121 | UTF8::str_replace('\\', '\\\\', $replacement) |
127 | 122 | ); |