@@ -18,9 +18,9 @@ |
||
18 | 18 | /** |
19 | 19 | * Replaces all occurrences of $search in $str by $replacement. |
20 | 20 | * |
21 | - * @param string|array $search The needle to search for. |
|
21 | + * @param string $search The needle to search for. |
|
22 | 22 | * |
23 | - * @param string|array $replacement The string to replace with. |
|
23 | + * @param string $replacement The string to replace with. |
|
24 | 24 | * |
25 | 25 | * @param bool $caseSensitive To enforce case-sensitivity or not. |
26 | 26 | * |
@@ -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 |
@@ -60,8 +58,7 @@ discard block |
||
60 | 58 | */ |
61 | 59 | public function replaceBeginning($search, $replacement) |
62 | 60 | { |
63 | - return $this->regexReplace |
|
64 | - ( |
|
61 | + return $this->regexReplace( |
|
65 | 62 | '^'.preg_quote($search, '/'), |
66 | 63 | UTF8::str_replace('\\', '\\\\', $replacement) |
67 | 64 | ); |
@@ -77,8 +74,7 @@ discard block |
||
77 | 74 | */ |
78 | 75 | public function replaceEnding($search, $replacement) |
79 | 76 | { |
80 | - return $this->regexReplace |
|
81 | - ( |
|
77 | + return $this->regexReplace( |
|
82 | 78 | preg_quote($search, '/').'$', |
83 | 79 | UTF8::str_replace('\\', '\\\\', $replacement) |
84 | 80 | ); |
@@ -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(), |
@@ -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 |
@@ -64,7 +64,10 @@ |
||
64 | 64 | */ |
65 | 65 | public function insert($substring, $index) |
66 | 66 | { |
67 | - if ($index > $this->getLength()) throw new \OutOfBoundsException(); |
|
67 | + if ($index > $this->getLength()) |
|
68 | + { |
|
69 | + throw new \OutOfBoundsException(); |
|
70 | + } |
|
68 | 71 | |
69 | 72 | $start = UTF8::substr |
70 | 73 | ( |
@@ -211,10 +211,10 @@ |
||
211 | 211 | */ |
212 | 212 | public function countSubstr($substring, $caseSensitive = true) |
213 | 213 | { |
214 | - if (!isset($this->scalarString[0])) |
|
215 | - { |
|
216 | - return 0; |
|
217 | - } |
|
214 | + if (!isset($this->scalarString[0])) |
|
215 | + { |
|
216 | + return 0; |
|
217 | + } |
|
218 | 218 | |
219 | 219 | if ($caseSensitive) |
220 | 220 | { |
@@ -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, |
@@ -35,12 +35,18 @@ discard block |
||
35 | 35 | public function between($start, $end, $offset = 0, $include = false) |
36 | 36 | { |
37 | 37 | $startIndex = $this->indexOf($start, $offset); |
38 | - if ($startIndex === false) return $this->newSelf(''); |
|
38 | + if ($startIndex === false) |
|
39 | + { |
|
40 | + return $this->newSelf(''); |
|
41 | + } |
|
39 | 42 | |
40 | 43 | $substrIndex = $startIndex + UTF8::strlen($start, $this->encoding); |
41 | 44 | |
42 | 45 | $endIndex = $this->indexOf($end, $substrIndex); |
43 | - if ($endIndex === false) return $this->newSelf(''); |
|
46 | + if ($endIndex === false) |
|
47 | + { |
|
48 | + return $this->newSelf(''); |
|
49 | + } |
|
44 | 50 | |
45 | 51 | $result = UTF8::substr |
46 | 52 | ( |
@@ -50,7 +56,10 @@ discard block |
||
50 | 56 | $this->encoding |
51 | 57 | ); |
52 | 58 | |
53 | - if ($include === true) $result = $start.$result.$end; |
|
59 | + if ($include === true) |
|
60 | + { |
|
61 | + $result = $start.$result.$end; |
|
62 | + } |
|
54 | 63 | |
55 | 64 | return $this->newSelf($result); |
56 | 65 | } |
@@ -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, |
@@ -26,10 +26,8 @@ discard block |
||
26 | 26 | { |
27 | 27 | if ($this->startsWith($substring)) |
28 | 28 | { |
29 | - return $this->newSelf |
|
30 | - ( |
|
31 | - UTF8::substr |
|
32 | - ( |
|
29 | + return $this->newSelf( |
|
30 | + UTF8::substr( |
|
33 | 31 | $this->scalarString, |
34 | 32 | UTF8::strlen($substring, $this->encoding), |
35 | 33 | null, |
@@ -52,10 +50,8 @@ discard block |
||
52 | 50 | { |
53 | 51 | if ($this->endsWith($substring)) |
54 | 52 | { |
55 | - return $this->newSelf |
|
56 | - ( |
|
57 | - UTF8::substr |
|
58 | - ( |
|
53 | + return $this->newSelf( |
|
54 | + UTF8::substr( |
|
59 | 55 | $this->scalarString, |
60 | 56 | 0, |
61 | 57 | $this->getLength() - UTF8::strlen($substring, $this->encoding), |
@@ -36,15 +36,14 @@ discard block |
||
36 | 36 | $substringLength = UTF8::strlen($substring, $this->encoding); |
37 | 37 | $length -= $substringLength; |
38 | 38 | |
39 | - $truncated = UTF8::substr |
|
40 | - ( |
|
39 | + $truncated = UTF8::substr( |
|
41 | 40 | $this->scalarString, |
42 | 41 | 0, |
43 | 42 | $length, |
44 | 43 | $this->encoding |
45 | 44 | ); |
46 | 45 | |
47 | - return $this->newSelf($truncated . $substring); |
|
46 | + return $this->newSelf($truncated.$substring); |
|
48 | 47 | } |
49 | 48 | |
50 | 49 | /** |
@@ -79,6 +78,6 @@ discard block |
||
79 | 78 | $truncated = UTF8::substr($truncated, 0, $lastPos, $this->encoding); |
80 | 79 | } |
81 | 80 | |
82 | - return $this->newSelf($truncated . $substring); |
|
81 | + return $this->newSelf($truncated.$substring); |
|
83 | 82 | } |
84 | 83 | } |
@@ -30,7 +30,10 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function truncate($length, $substring = '') |
32 | 32 | { |
33 | - if ($length >= $this->getLength()) return $this; |
|
33 | + if ($length >= $this->getLength()) |
|
34 | + { |
|
35 | + return $this; |
|
36 | + } |
|
34 | 37 | |
35 | 38 | // Need to further trim the string so we can append the substring |
36 | 39 | $substringLength = UTF8::strlen($substring, $this->encoding); |
@@ -63,7 +66,10 @@ discard block |
||
63 | 66 | */ |
64 | 67 | public function safeTruncate($length, $substring = '') |
65 | 68 | { |
66 | - if ($length >= $this->getLength()) return $this; |
|
69 | + if ($length >= $this->getLength()) |
|
70 | + { |
|
71 | + return $this; |
|
72 | + } |
|
67 | 73 | |
68 | 74 | // Need to further trim the string so we can append the substring |
69 | 75 | $substringLength = UTF8::strlen($substring, $this->encoding); |
@@ -76,7 +82,10 @@ discard block |
||
76 | 82 | { |
77 | 83 | // Find pos of the last occurrence of a space, get up to that |
78 | 84 | $lastPos = UTF8::strrpos($truncated, ' ', 0, $this->encoding); |
79 | - if (!is_integer($lastPos)) $lastPos = 0; |
|
85 | + if (!is_integer($lastPos)) |
|
86 | + { |
|
87 | + $lastPos = 0; |
|
88 | + } |
|
80 | 89 | $truncated = UTF8::substr($truncated, 0, $lastPos, $this->encoding); |
81 | 90 | } |
82 | 91 |