Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 081f5fa

Browse files
committed
Merge pull request #26 from samsonasik/substr-strpos
change substr with strpos when possible
2 parents 0089528 + f48547a commit 081f5fa

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function setFragment($fragment)
6767
public static function fromUnixPath($path)
6868
{
6969
$url = new static('file:');
70-
if (substr($path, 0, 1) == '/') {
70+
if (0 === strpos($path, '/')) {
7171
$url->setHost('');
7272
}
7373

src/Uri.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public static function getEscaper()
192192
public function isValid()
193193
{
194194
if ($this->host) {
195-
if (strlen($this->path) > 0 && substr($this->path, 0, 1) != '/') {
195+
if (strlen($this->path) > 0 && 0 !== strpos($this->path, '/')) {
196196
return false;
197197
}
198198
return true;
@@ -204,7 +204,7 @@ public function isValid()
204204

205205
if ($this->path) {
206206
// Check path-only (no host) URI
207-
if (substr($this->path, 0, 2) == '//') {
207+
if (0 === strpos($this->path, '//')) {
208208
return false;
209209
}
210210
return true;
@@ -231,7 +231,7 @@ public function isValidRelative()
231231

232232
if ($this->path) {
233233
// Check path-only (no host) URI
234-
if (substr($this->path, 0, 2) == '//') {
234+
if (0 === strpos($this->path, '//')) {
235235
return false;
236236
}
237237
return true;
@@ -337,7 +337,7 @@ public function parse($uri)
337337
}
338338

339339
// All that's left is the fragment
340-
if ($uri && substr($uri, 0, 1) == '#') {
340+
if ($uri && 0 === strpos($uri, '#')) {
341341
$this->setFragment(substr($uri, 1));
342342
}
343343

@@ -483,7 +483,7 @@ public function resolve($baseUri)
483483
$this->setQuery($baseUri->getQuery());
484484
}
485485
} else {
486-
if (substr($relPath, 0, 1) == '/') {
486+
if (0 === strpos($relPath, '/')) {
487487
$this->setPath(static::removePathDotSegments($relPath));
488488
} else {
489489
if ($baseUri->getHost() && ! $basePath) {
@@ -1105,21 +1105,21 @@ public static function removePathDotSegments($path)
11051105
}
11061106
$output = substr($output, 0, $lastSlashPos);
11071107
break;
1108-
case (substr($path, 0, 4) == '/../'):
1108+
case (0 === strpos($path, '/../')):
11091109
$path = '/' . substr($path, 4);
11101110
$lastSlashPos = strrpos($output, '/', -1);
11111111
if (false === $lastSlashPos) {
11121112
break;
11131113
}
11141114
$output = substr($output, 0, $lastSlashPos);
11151115
break;
1116-
case (substr($path, 0, 3) == '/./'):
1116+
case (0 === strpos($path, '/./')):
11171117
$path = substr($path, 2);
11181118
break;
1119-
case (substr($path, 0, 2) == './'):
1119+
case (0 === strpos($path, './')):
11201120
$path = substr($path, 2);
11211121
break;
1122-
case (substr($path, 0, 3) == '../'):
1122+
case (0 === strpos($path, '../')):
11231123
$path = substr($path, 3);
11241124
break;
11251125
default:

0 commit comments

Comments
 (0)