Skip to content

Commit 5401e70

Browse files
committed
Use str_starts_with()/str_ends_with() instead of substr()
1 parent da03d99 commit 5401e70

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/File/FileHelper.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use function ltrim;
1010
use function preg_match;
1111
use function rtrim;
12+
use function str_ends_with;
1213
use function str_replace;
1314
use function str_starts_with;
1415
use function strlen;
@@ -36,14 +37,13 @@ public function getWorkingDirectory(): string
3637
public function absolutizePath(string $path): string
3738
{
3839
if (DIRECTORY_SEPARATOR === '/') {
39-
if (substr($path, 0, 1) === '/') {
40-
return $path;
41-
}
42-
} else {
43-
if (substr($path, 1, 1) === ':') {
40+
if (str_starts_with($path, '/')) {
4441
return $path;
4542
}
43+
} elseif (substr($path, 1, 1) === ':') {
44+
return $path;
4645
}
46+
4747
if (preg_match('~^[a-z0-9+\-.]+://~i', $path) === 1) {
4848
return $path;
4949
}
@@ -87,12 +87,10 @@ public function normalizePath(string $originalPath, string $directorySeparator =
8787
continue;
8888
}
8989
if ($pathPart === '..') {
90-
/** @var string $removedPart */
9190
$removedPart = array_pop($normalizedPathParts);
92-
if ($scheme === 'phar' && substr($removedPart, -5) === '.phar') {
91+
if ($scheme === 'phar' && $removedPart !== null && str_ends_with($removedPart, '.phar')) {
9392
$scheme = null;
9493
}
95-
9694
} else {
9795
$normalizedPathParts[] = $pathPart;
9896
}

src/File/FuzzyRelativePathHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(
4040
$pathBeginning = null;
4141
$pathToTrimArray = null;
4242
$trimBeginning = static function (string $path): array {
43-
if (substr($path, 0, 1) === '/') {
43+
if (str_starts_with($path, '/')) {
4444
return [
4545
'/',
4646
substr($path, 1),

src/Type/IntersectionType.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use function ksort;
4343
use function md5;
4444
use function sprintf;
45+
use function str_starts_with;
4546
use function strlen;
4647
use function substr;
4748

@@ -388,7 +389,7 @@ private function describeItself(VerbosityLevel $level, bool $skipAccessoryTypes)
388389
}
389390

390391
if (
391-
substr($typeDescription, 0, strlen('array<')) === 'array<'
392+
str_starts_with($typeDescription, 'array<')
392393
&& in_array('array', $skipTypeNames, true)
393394
) {
394395
$nonEmpty = false;

0 commit comments

Comments
 (0)