@@ -396,7 +396,8 @@ private function checkClass(string $class, string $file = null): void
396
396
}
397
397
398
398
if (!$ exists ) {
399
- if (str_contains ($ class , '/ ' )) {
399
+ // Because this file is loading classes, it cannot use any polyfill
400
+ if (false !== strpos ($ class , '/ ' )) {
400
401
throw new \RuntimeException (sprintf ('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/". ' , $ class ));
401
402
}
402
403
@@ -419,7 +420,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
419
420
}
420
421
$ deprecations = [];
421
422
422
- $ className = str_contains ($ class , "@anonymous \0" ) ? (get_parent_class ($ class ) ?: key (class_implements ($ class )) ?: 'class ' ).'@anonymous ' : $ class ;
423
+ $ className = false !== strpos ($ class , "@anonymous \0" ) ? (get_parent_class ($ class ) ?: key (class_implements ($ class )) ?: 'class ' ).'@anonymous ' : $ class ;
423
424
424
425
// Don't trigger deprecations for classes in the same vendor
425
426
if ($ class !== $ className ) {
@@ -435,17 +436,17 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
435
436
// Detect annotations on the class
436
437
if (false !== $ doc = $ refl ->getDocComment ()) {
437
438
foreach (['final ' , 'deprecated ' , 'internal ' ] as $ annotation ) {
438
- if (str_contains ($ doc , $ annotation ) && preg_match ('#\n\s+\* @ ' .$ annotation .'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s ' , $ doc , $ notice )) {
439
+ if (false !== strpos ($ doc , $ annotation ) && preg_match ('#\n\s+\* @ ' .$ annotation .'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s ' , $ doc , $ notice )) {
439
440
self ::$ {$ annotation }[$ class ] = isset ($ notice [1 ]) ? preg_replace ('#\.?\r?\n( \*)? *(?= |\r?\n|$)# ' , '' , $ notice [1 ]) : '' ;
440
441
}
441
442
}
442
443
443
- if ($ refl ->isInterface () && str_contains ($ doc , 'method ' ) && preg_match_all ('#\n \* @method\s+(static\s+)?+([\w\|&\[\] \\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))# ' , $ doc , $ notice , \PREG_SET_ORDER )) {
444
+ if ($ refl ->isInterface () && false !== strpos ($ doc , 'method ' ) && preg_match_all ('#\n \* @method\s+(static\s+)?+([\w\|&\[\] \\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))# ' , $ doc , $ notice , \PREG_SET_ORDER )) {
444
445
foreach ($ notice as $ method ) {
445
446
$ static = '' !== $ method [1 ] && !empty ($ method [2 ]);
446
447
$ name = $ method [3 ];
447
448
$ description = $ method [4 ] ?? null ;
448
- if (! str_contains ($ name , '( ' )) {
449
+ if (false === strpos ($ name , '( ' )) {
449
450
$ name .= '() ' ;
450
451
}
451
452
if (null !== $ description ) {
@@ -496,7 +497,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
496
497
}
497
498
} elseif (!$ refl ->isInterface ()) {
498
499
if (!strncmp ($ vendor , str_replace ('_ ' , '\\' , $ use ), $ vendorLen )
499
- && str_starts_with ($ className , 'Symfony \\' )
500
+ && 0 === strpos ($ className , 'Symfony \\' )
500
501
&& (!class_exists (InstalledVersions::class)
501
502
|| 'symfony/symfony ' !== InstalledVersions::getRootPackage ()['name ' ])
502
503
) {
@@ -597,12 +598,12 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
597
598
598
599
$ forcePatchTypes = $ this ->patchTypes ['force ' ];
599
600
600
- if ($ canAddReturnType = null !== $ forcePatchTypes && ! str_contains ($ method ->getFileName (), \DIRECTORY_SEPARATOR .'vendor ' .\DIRECTORY_SEPARATOR )) {
601
+ if ($ canAddReturnType = null !== $ forcePatchTypes && false === strpos ($ method ->getFileName (), \DIRECTORY_SEPARATOR .'vendor ' .\DIRECTORY_SEPARATOR )) {
601
602
if ('void ' !== (self ::MAGIC_METHODS [$ method ->name ] ?? 'void ' )) {
602
603
$ this ->patchTypes ['force ' ] = $ forcePatchTypes ?: 'docblock ' ;
603
604
}
604
605
605
- $ canAddReturnType = str_contains ($ refl ->getFileName (), \DIRECTORY_SEPARATOR .'Tests ' .\DIRECTORY_SEPARATOR )
606
+ $ canAddReturnType = false !== strpos ($ refl ->getFileName (), \DIRECTORY_SEPARATOR .'Tests ' .\DIRECTORY_SEPARATOR )
606
607
|| $ refl ->isFinal ()
607
608
|| $ method ->isFinal ()
608
609
|| $ method ->isPrivate ()
@@ -623,8 +624,8 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
623
624
$ this ->patchMethod ($ method , $ returnType , $ declaringFile , $ normalizedType );
624
625
}
625
626
626
- if (! str_contains ($ doc , '* @deprecated ' ) && strncmp ($ ns , $ declaringClass , $ len )) {
627
- if ($ canAddReturnType && 'docblock ' === $ this ->patchTypes ['force ' ] && ! str_contains ($ method ->getFileName (), \DIRECTORY_SEPARATOR .'vendor ' .\DIRECTORY_SEPARATOR )) {
627
+ if (false === strpos ($ doc , '* @deprecated ' ) && strncmp ($ ns , $ declaringClass , $ len )) {
628
+ if ($ canAddReturnType && 'docblock ' === $ this ->patchTypes ['force ' ] && false === strpos ($ method ->getFileName (), \DIRECTORY_SEPARATOR .'vendor ' .\DIRECTORY_SEPARATOR )) {
628
629
$ this ->patchMethod ($ method , $ returnType , $ declaringFile , $ normalizedType );
629
630
} elseif ('' !== $ declaringClass && $ this ->patchTypes ['deprecations ' ]) {
630
631
$ deprecations [] = sprintf ('Method "%s::%s()" will return "%s" as of its next major version. Doing the same in %s "%s" will be required when upgrading. ' , $ declaringClass , $ method ->name , $ normalizedType , interface_exists ($ declaringClass ) ? 'implementation ' : 'child class ' , $ className );
@@ -640,7 +641,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
640
641
641
642
$ matches = [];
642
643
643
- if (!$ method ->hasReturnType () && ((str_contains ($ doc , '@return ' ) && preg_match ('/\n\s+\* @return +([^\s<(]+)/ ' , $ doc , $ matches )) || 'void ' !== (self ::MAGIC_METHODS [$ method ->name ] ?? 'void ' ))) {
644
+ if (!$ method ->hasReturnType () && ((false !== strpos ($ doc , '@return ' ) && preg_match ('/\n\s+\* @return +([^\s<(]+)/ ' , $ doc , $ matches )) || 'void ' !== (self ::MAGIC_METHODS [$ method ->name ] ?? 'void ' ))) {
644
645
$ matches = $ matches ?: [1 => self ::MAGIC_METHODS [$ method ->name ]];
645
646
$ this ->setReturnType ($ matches [1 ], $ method , $ parent );
646
647
@@ -662,14 +663,14 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
662
663
$ finalOrInternal = false ;
663
664
664
665
foreach (['final ' , 'internal ' ] as $ annotation ) {
665
- if (str_contains ($ doc , $ annotation ) && preg_match ('#\n\s+\* @ ' .$ annotation .'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s ' , $ doc , $ notice )) {
666
+ if (false !== strpos ($ doc , $ annotation ) && preg_match ('#\n\s+\* @ ' .$ annotation .'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$|\r?\n)#s ' , $ doc , $ notice )) {
666
667
$ message = isset ($ notice [1 ]) ? preg_replace ('#\.?\r?\n( \*)? *(?= |\r?\n|$)# ' , '' , $ notice [1 ]) : '' ;
667
668
self ::$ {$ annotation .'Methods ' }[$ class ][$ method ->name ] = [$ class , $ message ];
668
669
$ finalOrInternal = true ;
669
670
}
670
671
}
671
672
672
- if ($ finalOrInternal || $ method ->isConstructor () || ! str_contains ($ doc , '@param ' ) || StatelessInvocation::class === $ class ) {
673
+ if ($ finalOrInternal || $ method ->isConstructor () || false === strpos ($ doc , '@param ' ) || StatelessInvocation::class === $ class ) {
673
674
continue ;
674
675
}
675
676
if (!preg_match_all ('#\n\s+\* @param +((?(?!callable *\().*?|callable *\(.*\).*?))(?<= )\$([a-zA-Z0-9_\x7f-\xff]++)# ' , $ doc , $ matches , \PREG_SET_ORDER )) {
@@ -850,7 +851,7 @@ private function setReturnType(string $types, \ReflectionMethod $method, ?string
850
851
$ iterable = $ object = true ;
851
852
foreach ($ typesMap as $ n => $ t ) {
852
853
if ('null ' !== $ n ) {
853
- $ iterable = $ iterable && (\in_array ($ n , ['array ' , 'iterable ' ]) || str_contains ($ n , 'Iterator ' ));
854
+ $ iterable = $ iterable && (\in_array ($ n , ['array ' , 'iterable ' ]) || false !== strpos ($ n , 'Iterator ' ));
854
855
$ object = $ object && (\in_array ($ n , ['callable ' , 'object ' , '$this ' , 'static ' ]) || !isset (self ::SPECIAL_RETURN_TYPES [$ n ]));
855
856
}
856
857
}
@@ -1034,15 +1035,15 @@ private static function getUseStatements(string $file): array
1034
1035
break ;
1035
1036
}
1036
1037
1037
- if (str_starts_with ($ file [$ i ], 'namespace ' )) {
1038
+ if (0 === strpos ($ file [$ i ], 'namespace ' )) {
1038
1039
$ namespace = substr ($ file [$ i ], \strlen ('namespace ' ), -2 ).'\\' ;
1039
1040
$ useOffset = $ i + 2 ;
1040
1041
}
1041
1042
1042
- if (str_starts_with ($ file [$ i ], 'use ' )) {
1043
+ if (0 === strpos ($ file [$ i ], 'use ' )) {
1043
1044
$ useOffset = $ i ;
1044
1045
1045
- for (; str_starts_with ($ file [$ i ], 'use ' ); ++$ i ) {
1046
+ for (; 0 === strpos ($ file [$ i ], 'use ' ); ++$ i ) {
1046
1047
$ u = explode (' as ' , substr ($ file [$ i ], 4 , -2 ), 2 );
1047
1048
1048
1049
if (1 === \count ($ u )) {
0 commit comments