@@ -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(), |
@@ -110,8 +110,7 @@ |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | $toBeAppended = $string; |
113 | - } |
|
114 | - else |
|
113 | + } else |
|
115 | 114 | { |
116 | 115 | // Ensure the incoming string is string like... Str will throw |
117 | 116 | // exceptions if not. We also make the assumption that any "scalar" |
@@ -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, |
@@ -100,8 +100,7 @@ discard block |
||
100 | 100 | ( |
101 | 101 | 'Passed value cannot be an array' |
102 | 102 | ); |
103 | - } |
|
104 | - elseif (is_object($string) && !method_exists($string, '__toString')) |
|
103 | + } elseif (is_object($string) && !method_exists($string, '__toString')) |
|
105 | 104 | { |
106 | 105 | throw new \InvalidArgumentException |
107 | 106 | ( |
@@ -119,8 +118,7 @@ discard block |
||
119 | 118 | if ($encoding !== null) |
120 | 119 | { |
121 | 120 | $this->encoding = $encoding; |
122 | - } |
|
123 | - else |
|
121 | + } else |
|
124 | 122 | { |
125 | 123 | $this->encoding = mb_internal_encoding(); |
126 | 124 | } |
@@ -199,13 +197,11 @@ discard block |
||
199 | 197 | { |
200 | 198 | // Convert the scalar string to a Str Object |
201 | 199 | $strObjects[$key] = $this->newSelf($value); |
202 | - } |
|
203 | - elseif (is_array($value)) |
|
200 | + } elseif (is_array($value)) |
|
204 | 201 | { |
205 | 202 | // Recurse into the array |
206 | 203 | $strObjects[$key] = $this->newSelfs($value); |
207 | - } |
|
208 | - else |
|
204 | + } else |
|
209 | 205 | { |
210 | 206 | // We don't know what it is do do nothing to it |
211 | 207 | $strObjects[$key] = $value; |
@@ -259,7 +255,9 @@ discard block |
||
259 | 255 | { |
260 | 256 | $index = (int)$index; |
261 | 257 | |
262 | - if ($index >= 0) return ($this->getLength() > $index); |
|
258 | + if ($index >= 0) { |
|
259 | + return ($this->getLength() > $index); |
|
260 | + } |
|
263 | 261 | |
264 | 262 | return ($this->getLength() >= abs($index)); |
265 | 263 | } |
@@ -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, |
@@ -88,7 +88,9 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function isJson() |
90 | 90 | { |
91 | - if ($this->getLength() === 0) return false; |
|
91 | + if ($this->getLength() === 0) { |
|
92 | + return false; |
|
93 | + } |
|
92 | 94 | |
93 | 95 | json_decode($this->scalarString); |
94 | 96 | |
@@ -102,7 +104,9 @@ discard block |
||
102 | 104 | */ |
103 | 105 | public function isSerialized() |
104 | 106 | { |
105 | - if ($this->getLength() === 0) return false; |
|
107 | + if ($this->getLength() === 0) { |
|
108 | + return false; |
|
109 | + } |
|
106 | 110 | |
107 | 111 | /** @noinspection PhpUsageOfSilenceOperatorInspection */ |
108 | 112 | return |
@@ -120,7 +124,9 @@ discard block |
||
120 | 124 | public function isBase64() |
121 | 125 | { |
122 | 126 | // An empty string is by definition not encoded. |
123 | - if ($this->getLength() === 0) return false; |
|
127 | + if ($this->getLength() === 0) { |
|
128 | + return false; |
|
129 | + } |
|
124 | 130 | |
125 | 131 | // Grab the current string value. |
126 | 132 | $possiblyEncoded = $this->scalarString; |
@@ -129,7 +135,9 @@ discard block |
||
129 | 135 | $decoded = base64_decode($possiblyEncoded, true); |
130 | 136 | |
131 | 137 | // If we get false it can't be base64 |
132 | - if ($decoded === false) return false; |
|
138 | + if ($decoded === false) { |
|
139 | + return false; |
|
140 | + } |
|
133 | 141 | |
134 | 142 | // Lets double check |
135 | 143 | return (base64_encode($decoded) === $this->scalarString); |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | if ($this->startsWith($substring)) |
28 | 28 | { |
29 | 29 | return $this; |
30 | - } |
|
31 | - else |
|
30 | + } else |
|
32 | 31 | { |
33 | 32 | return $this->newSelf($substring.$this->scalarString); |
34 | 33 | } |
@@ -46,8 +45,7 @@ discard block |
||
46 | 45 | if ($this->endsWith($substring)) |
47 | 46 | { |
48 | 47 | return $this; |
49 | - } |
|
50 | - else |
|
48 | + } else |
|
51 | 49 | { |
52 | 50 | return $this->newSelf($this->scalarString.$substring); |
53 | 51 | } |
@@ -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,9 @@ discard block |
||
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 | + throw new \OutOfBoundsException(); |
|
69 | + } |
|
68 | 70 | |
69 | 71 | $start = UTF8::substr |
70 | 72 | ( |
@@ -149,16 +151,13 @@ discard block |
||
149 | 151 | if ($end === null) |
150 | 152 | { |
151 | 153 | $length = $this->getLength(); |
152 | - } |
|
153 | - elseif ($end >= 0 && $end <= $start) |
|
154 | + } elseif ($end >= 0 && $end <= $start) |
|
154 | 155 | { |
155 | 156 | return $this->newSelf(''); |
156 | - } |
|
157 | - elseif ($end < 0) |
|
157 | + } elseif ($end < 0) |
|
158 | 158 | { |
159 | 159 | $length = $this->getLength() + $end - $start; |
160 | - } |
|
161 | - else |
|
160 | + } else |
|
162 | 161 | { |
163 | 162 | $length = $end - $start; |
164 | 163 | } |
@@ -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,16 @@ 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 | + return $this->newSelf(''); |
|
40 | + } |
|
39 | 41 | |
40 | 42 | $substrIndex = $startIndex + UTF8::strlen($start, $this->encoding); |
41 | 43 | |
42 | 44 | $endIndex = $this->indexOf($end, $substrIndex); |
43 | - if ($endIndex === false) return $this->newSelf(''); |
|
45 | + if ($endIndex === false) { |
|
46 | + return $this->newSelf(''); |
|
47 | + } |
|
44 | 48 | |
45 | 49 | $result = UTF8::substr |
46 | 50 | ( |
@@ -50,7 +54,9 @@ discard block |
||
50 | 54 | $this->encoding |
51 | 55 | ); |
52 | 56 | |
53 | - if ($include === true) $result = $start.$result.$end; |
|
57 | + if ($include === true) { |
|
58 | + $result = $start.$result.$end; |
|
59 | + } |
|
54 | 60 | |
55 | 61 | return $this->newSelf($result); |
56 | 62 | } |
@@ -72,8 +72,7 @@ |
||
72 | 72 | if (!$chars) |
73 | 73 | { |
74 | 74 | return '[:space:]'; |
75 | - } |
|
76 | - else |
|
75 | + } else |
|
77 | 76 | { |
78 | 77 | return preg_quote($chars, $this->regexDelimiter); |
79 | 78 | } |