diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index e5977dabf4..6ba768e1e3 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -595,7 +595,7 @@ private function processStmtNode( } $isFromTrait = $stmt->getAttribute('originalTraitMethodName') === '__construct'; - if ($stmt->name->toLowerString() === '__construct' || $isFromTrait) { + if ($isFromTrait || $stmt->name->toLowerString() === '__construct') { foreach ($stmt->params as $param) { if ($param->flags === 0) { continue; diff --git a/src/File/FileHelper.php b/src/File/FileHelper.php index 33f4878cb4..06bca961f3 100644 --- a/src/File/FileHelper.php +++ b/src/File/FileHelper.php @@ -9,6 +9,7 @@ use function ltrim; use function preg_match; use function rtrim; +use function str_ends_with; use function str_replace; use function str_starts_with; use function strlen; @@ -36,14 +37,13 @@ public function getWorkingDirectory(): string public function absolutizePath(string $path): string { if (DIRECTORY_SEPARATOR === '/') { - if (substr($path, 0, 1) === '/') { - return $path; - } - } else { - if (substr($path, 1, 1) === ':') { + if (str_starts_with($path, '/')) { return $path; } + } elseif (substr($path, 1, 1) === ':') { + return $path; } + if (preg_match('~^[a-z0-9+\-.]+://~i', $path) === 1) { return $path; } @@ -87,12 +87,10 @@ public function normalizePath(string $originalPath, string $directorySeparator = continue; } if ($pathPart === '..') { - /** @var string $removedPart */ $removedPart = array_pop($normalizedPathParts); - if ($scheme === 'phar' && substr($removedPart, -5) === '.phar') { + if ($scheme === 'phar' && $removedPart !== null && str_ends_with($removedPart, '.phar')) { $scheme = null; } - } else { $normalizedPathParts[] = $pathPart; } diff --git a/src/File/FuzzyRelativePathHelper.php b/src/File/FuzzyRelativePathHelper.php index 3654c10c08..dc2d44e505 100644 --- a/src/File/FuzzyRelativePathHelper.php +++ b/src/File/FuzzyRelativePathHelper.php @@ -40,7 +40,7 @@ public function __construct( $pathBeginning = null; $pathToTrimArray = null; $trimBeginning = static function (string $path): array { - if (substr($path, 0, 1) === '/') { + if (str_starts_with($path, '/')) { return [ '/', substr($path, 1), diff --git a/src/Reflection/BetterReflection/SourceLocator/PhpFileCleaner.php b/src/Reflection/BetterReflection/SourceLocator/PhpFileCleaner.php index 278aa19b04..6e76066fee 100644 --- a/src/Reflection/BetterReflection/SourceLocator/PhpFileCleaner.php +++ b/src/Reflection/BetterReflection/SourceLocator/PhpFileCleaner.php @@ -233,7 +233,7 @@ private function skipComment(): void private function skipToNewline(): void { while ($this->index < $this->len) { - if ($this->contents[$this->index] === "\r" || $this->contents[$this->index] === "\n") { + if (in_array($this->contents[$this->index], ["\r", "\n"], true)) { return; } $this->index += 1; diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index 91e1205189..b8615874f2 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -790,7 +790,7 @@ public function getDivType(Expr $left, Expr $right, callable $getTypeCallback): throw new ShouldNotHappenException(); } - if ($rightNumberType->getValue() === 0 || $rightNumberType->getValue() === 0.0) { + if (in_array($rightNumberType->getValue(), [0, 0.0], true)) { return new ErrorType(); } diff --git a/src/Type/IntersectionType.php b/src/Type/IntersectionType.php index cdf572bdcf..fbec19866d 100644 --- a/src/Type/IntersectionType.php +++ b/src/Type/IntersectionType.php @@ -42,6 +42,7 @@ use function ksort; use function md5; use function sprintf; +use function str_starts_with; use function strlen; use function substr; @@ -388,7 +389,7 @@ private function describeItself(VerbosityLevel $level, bool $skipAccessoryTypes) } if ( - substr($typeDescription, 0, strlen('array<')) === 'array<' + str_starts_with($typeDescription, 'array<') && in_array('array', $skipTypeNames, true) ) { $nonEmpty = false; diff --git a/src/Type/ObjectType.php b/src/Type/ObjectType.php index 5bed6a0ba8..6bba05fa01 100644 --- a/src/Type/ObjectType.php +++ b/src/Type/ObjectType.php @@ -375,12 +375,12 @@ public function isSuperTypeOf(Type $type): TrinaryLogic } $reflectionProvider = ReflectionProviderStaticAccessor::getInstance(); + $thisClassReflection = $this->getClassReflection(); - if ($this->getClassReflection() === null || !$reflectionProvider->hasClass($thatClassNames[0])) { + if ($thisClassReflection === null || !$reflectionProvider->hasClass($thatClassNames[0])) { return self::$superTypes[$thisDescription][$description] = TrinaryLogic::createMaybe(); } - $thisClassReflection = $this->getClassReflection(); $thatClassReflection = $reflectionProvider->getClass($thatClassNames[0]); if ($thisClassReflection->isTrait() || $thatClassReflection->isTrait()) {