@@ -203,28 +203,26 @@ public static function delimiter( ?string $char = null ) : string
203
203
*/
204
204
public static function explode ( string $ delimiter , string $ string , int $ limit = PHP_INT_MAX ) : self
205
205
{
206
- return new static ( function () use ( $ delimiter , $ string , $ limit ) {
206
+ if ( $ delimiter !== '' ) {
207
+ return new static ( explode ( $ delimiter , $ string , $ limit ) );
208
+ }
207
209
208
- if ( $ delimiter !== '' ) {
209
- return explode ( $ delimiter , $ string , $ limit );
210
- }
210
+ $ limit = $ limit ?: 1 ;
211
+ $ parts = mb_str_split ( $ string );
211
212
212
- $ limit = $ limit ?: 1 ;
213
- $ parts = mb_str_split ( $ string );
213
+ if ( $ limit < 1 ) {
214
+ return new static ( array_slice ( $ parts , 0 , $ limit ) );
215
+ }
214
216
215
- if ( $ limit < 1 ) {
216
- return array_slice ( $ parts , 0 , $ limit );
217
- }
217
+ if ( $ limit < count ( $ parts ) )
218
+ {
219
+ $ result = array_slice ( $ parts , 0 , $ limit );
220
+ $ result [] = join ( '' , array_slice ( $ parts , $ limit ) );
218
221
219
- if ( $ limit < count ( $ parts ) )
220
- {
221
- $ result = array_slice ( $ parts , 0 , $ limit );
222
- $ result [] = join ( '' , array_slice ( $ parts , $ limit ) );
223
- return $ result ;
224
- }
222
+ return new static ( $ result );
223
+ }
225
224
226
- return $ parts ;
227
- } );
225
+ return new static ( $ parts );
228
226
}
229
227
230
228
@@ -286,14 +284,11 @@ public static function from( $elements = [] ) : self
286
284
*/
287
285
public static function fromJson ( string $ json , int $ options = JSON_BIGINT_AS_STRING ) : self
288
286
{
289
- return new static ( function () use ( $ json , $ options ) {
290
-
291
- if ( ( $ result = json_decode ( $ json , true , 512 , $ options ) ) !== null ) {
292
- return $ result ;
293
- }
287
+ if ( ( $ result = json_decode ( $ json , true , 512 , $ options ) ) !== null ) {
288
+ return new static ( $ result );
289
+ }
294
290
295
- throw new \RuntimeException ( 'Not a valid JSON string: ' . $ json );
296
- } );
291
+ throw new \RuntimeException ( 'Not a valid JSON string: ' . $ json );
297
292
}
298
293
299
294
@@ -357,17 +352,14 @@ public static function method( string $method, ?\Closure $fcn = null ) : ?\Closu
357
352
*/
358
353
public static function times ( int $ num , \Closure $ callback ) : self
359
354
{
360
- return new static ( function () use ( $ num , $ callback ) {
361
-
362
- $ list = [];
355
+ $ list = [];
363
356
364
- for ( $ i = 0 ; $ i < $ num ; $ i ++ ) {
365
- $ key = $ i ;
366
- $ list [$ key ] = $ callback ( $ i , $ key );
367
- }
357
+ for ( $ i = 0 ; $ i < $ num ; $ i ++ ) {
358
+ $ key = $ i ;
359
+ $ list [$ key ] = $ callback ( $ i , $ key );
360
+ }
368
361
369
- return $ list ;
370
- } );
362
+ return new static ( $ list );
371
363
}
372
364
373
365
0 commit comments