1
1
<?php
2
2
3
- namespace Markenwerk \StringBuilder ;
3
+ namespace ChromaX \StringBuilder ;
4
4
5
- use Markenwerk \StringBuilder \Util \ArgumentValidator ;
5
+ use ChromaX \StringBuilder \Util \ArgumentValidator ;
6
+ use InvalidArgumentException ;
6
7
7
8
/**
8
9
* Class StringBuilder
9
10
*
10
- * @package Markenwerk \StringBuilder
11
+ * @package ChromaX \StringBuilder
11
12
*/
12
13
class StringBuilder
13
14
{
@@ -23,7 +24,7 @@ class StringBuilder
23
24
* Takes an initial string as argument
24
25
*
25
26
* @param null $string
26
- * @throws \ InvalidArgumentException
27
+ * @throws InvalidArgumentException
27
28
*/
28
29
public function __construct ($ string = null )
29
30
{
@@ -38,7 +39,7 @@ public function __construct($string = null)
38
39
*
39
40
* @param string $string
40
41
* @return $this
41
- * @throws \ InvalidArgumentException
42
+ * @throws InvalidArgumentException
42
43
*/
43
44
public function append ($ string )
44
45
{
@@ -52,7 +53,7 @@ public function append($string)
52
53
*
53
54
* @param string $string
54
55
* @return $this
55
- * @throws \ InvalidArgumentException
56
+ * @throws InvalidArgumentException
56
57
*/
57
58
public function prepend ($ string )
58
59
{
@@ -67,14 +68,14 @@ public function prepend($string)
67
68
* @param int $position
68
69
* @param string $string
69
70
* @return $this
70
- * @throws \ InvalidArgumentException
71
+ * @throws InvalidArgumentException
71
72
*/
72
73
public function insert ($ position , $ string )
73
74
{
74
75
ArgumentValidator::validateUnsignedInteger ($ position );
75
76
ArgumentValidator::validateScalar ($ string );
76
77
if ($ position >= $ this ->length ()) {
77
- throw new \ InvalidArgumentException ('Position invalid ' );
78
+ throw new InvalidArgumentException ('Position invalid ' );
78
79
}
79
80
$ this ->string = mb_substr ($ this ->string , 0 , $ position ) . (string )$ string . mb_substr ($ this ->string , $ position );
80
81
return $ this ;
@@ -87,18 +88,18 @@ public function insert($position, $string)
87
88
* @param int $length
88
89
* @param string $string
89
90
* @return $this
90
- * @throws \ InvalidArgumentException
91
+ * @throws InvalidArgumentException
91
92
*/
92
93
public function replace ($ position , $ length , $ string )
93
94
{
94
95
ArgumentValidator::validateUnsignedInteger ($ position );
95
96
ArgumentValidator::validateUnsignedInteger ($ length );
96
97
ArgumentValidator::validateScalar ($ string );
97
98
if ($ position >= $ this ->length ()) {
98
- throw new \ InvalidArgumentException ('Position invalid ' );
99
+ throw new InvalidArgumentException ('Position invalid ' );
99
100
}
100
101
if ($ position + $ length > $ this ->length ()) {
101
- throw new \ InvalidArgumentException ('Length invalid ' );
102
+ throw new InvalidArgumentException ('Length invalid ' );
102
103
}
103
104
$ this ->string = mb_substr ($ this ->string , 0 , $ position ) . (string )$ string . mb_substr ($ this ->string , $ position + $ length );
104
105
return $ this ;
@@ -110,17 +111,17 @@ public function replace($position, $length, $string)
110
111
* @param int $position
111
112
* @param string $character
112
113
* @return $this
113
- * @throws \ InvalidArgumentException
114
+ * @throws InvalidArgumentException
114
115
*/
115
116
public function setCharAt ($ position , $ character )
116
117
{
117
118
ArgumentValidator::validateUnsignedInteger ($ position );
118
119
ArgumentValidator::validateScalar ($ character );
119
120
if ($ position >= $ this ->length ()) {
120
- throw new \ InvalidArgumentException ('Position invalid ' );
121
+ throw new InvalidArgumentException ('Position invalid ' );
121
122
}
122
123
if (mb_strlen ((string )$ character ) !== 1 ) {
123
- throw new \ InvalidArgumentException ('Expected a scalar value of length 1 ' );
124
+ throw new InvalidArgumentException ('Expected a scalar value of length 1 ' );
124
125
}
125
126
$ this ->string = mb_substr ($ this ->string , 0 , $ position ) . (string )$ character . mb_substr ($ this ->string , $ position + 1 );
126
127
return $ this ;
@@ -148,14 +149,14 @@ public function reverse()
148
149
* @param int $position
149
150
* @param int $length
150
151
* @return $this
151
- * @throws \ InvalidArgumentException
152
+ * @throws InvalidArgumentException
152
153
*/
153
154
public function delete ($ position , $ length = null )
154
155
{
155
156
ArgumentValidator::validateUnsignedInteger ($ position );
156
157
ArgumentValidator::validateUnsignedIntegerOrNull ($ length );
157
158
if ($ position >= $ this ->length ()) {
158
- throw new \ InvalidArgumentException ('Position invalid ' );
159
+ throw new InvalidArgumentException ('Position invalid ' );
159
160
}
160
161
if ($ length === null ) {
161
162
$ this ->string = mb_substr ($ this ->string , 0 , $ position );
@@ -170,13 +171,13 @@ public function delete($position, $length = null)
170
171
*
171
172
* @param int $position
172
173
* @return $this
173
- * @throws \ InvalidArgumentException
174
+ * @throws InvalidArgumentException
174
175
*/
175
176
public function deleteCharAt ($ position )
176
177
{
177
178
ArgumentValidator::validateUnsignedInteger ($ position );
178
179
if ($ position >= $ this ->length ()) {
179
- throw new \ InvalidArgumentException ('Position invalid ' );
180
+ throw new InvalidArgumentException ('Position invalid ' );
180
181
}
181
182
$ this ->string = mb_substr ($ this ->string , 0 , $ position ) . mb_substr ($ this ->string , $ position + 1 );
182
183
return $ this ;
@@ -187,7 +188,7 @@ public function deleteCharAt($position)
187
188
*
188
189
* @param string $substring
189
190
* @return bool
190
- * @throws \ InvalidArgumentException
191
+ * @throws InvalidArgumentException
191
192
*/
192
193
public function contains ($ substring )
193
194
{
@@ -203,7 +204,7 @@ public function contains($substring)
203
204
* @param string $string
204
205
* @param int $offset
205
206
* @return int
206
- * @throws \ InvalidArgumentException
207
+ * @throws InvalidArgumentException
207
208
*/
208
209
public function indexOf ($ string , $ offset = 0 )
209
210
{
@@ -222,7 +223,7 @@ public function indexOf($string, $offset = 0)
222
223
* @param string $string
223
224
* @param int $offset
224
225
* @return int
225
- * @throws \ InvalidArgumentException
226
+ * @throws InvalidArgumentException
226
227
*/
227
228
public function lastIndexOf ($ string , $ offset = 0 )
228
229
{
@@ -258,13 +259,13 @@ public function length()
258
259
*
259
260
* @param int $position
260
261
* @return string
261
- * @throws \ InvalidArgumentException
262
+ * @throws InvalidArgumentException
262
263
*/
263
264
public function charAt ($ position )
264
265
{
265
266
ArgumentValidator::validateUnsignedInteger ($ position );
266
267
if ($ position >= $ this ->length ()) {
267
- throw new \ InvalidArgumentException ('Position invalid ' );
268
+ throw new InvalidArgumentException ('Position invalid ' );
268
269
}
269
270
return mb_substr ($ this ->string , $ position , 1 );
270
271
}
@@ -295,14 +296,14 @@ public function lastChar()
295
296
* @param int $startPosition
296
297
* @param int $length
297
298
* @return string
298
- * @throws \ InvalidArgumentException
299
+ * @throws InvalidArgumentException
299
300
*/
300
301
public function buildSubstring ($ startPosition , $ length = null )
301
302
{
302
303
ArgumentValidator::validateUnsignedInteger ($ startPosition );
303
304
ArgumentValidator::validateUnsignedIntegerOrNull ($ length );
304
305
if ($ startPosition >= $ this ->length ()) {
305
- throw new \ InvalidArgumentException ('Start position ' . (string )$ startPosition . ' invalid ' );
306
+ throw new InvalidArgumentException ('Start position ' . (string )$ startPosition . ' invalid ' );
306
307
}
307
308
if ($ length === null ) {
308
309
return mb_substr ($ this ->string , $ startPosition );
0 commit comments