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

Commit

Permalink
Merge pull request #26 from samsonasik/substr-strpos
Browse files Browse the repository at this point in the history
change substr with strpos when possible
  • Loading branch information
weierophinney committed Feb 26, 2019
2 parents 0089528 + f48547a commit 081f5fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/File.php
Expand Up @@ -67,7 +67,7 @@ public function setFragment($fragment)
public static function fromUnixPath($path)
{
$url = new static('file:');
if (substr($path, 0, 1) == '/') {
if (0 === strpos($path, '/')) {
$url->setHost('');
}

Expand Down
18 changes: 9 additions & 9 deletions src/Uri.php
Expand Up @@ -192,7 +192,7 @@ public static function getEscaper()
public function isValid()
{
if ($this->host) {
if (strlen($this->path) > 0 && substr($this->path, 0, 1) != '/') {
if (strlen($this->path) > 0 && 0 !== strpos($this->path, '/')) {
return false;
}
return true;
Expand All @@ -204,7 +204,7 @@ public function isValid()

if ($this->path) {
// Check path-only (no host) URI
if (substr($this->path, 0, 2) == '//') {
if (0 === strpos($this->path, '//')) {
return false;
}
return true;
Expand All @@ -231,7 +231,7 @@ public function isValidRelative()

if ($this->path) {
// Check path-only (no host) URI
if (substr($this->path, 0, 2) == '//') {
if (0 === strpos($this->path, '//')) {
return false;
}
return true;
Expand Down Expand Up @@ -337,7 +337,7 @@ public function parse($uri)
}

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

Expand Down Expand Up @@ -483,7 +483,7 @@ public function resolve($baseUri)
$this->setQuery($baseUri->getQuery());
}
} else {
if (substr($relPath, 0, 1) == '/') {
if (0 === strpos($relPath, '/')) {
$this->setPath(static::removePathDotSegments($relPath));
} else {
if ($baseUri->getHost() && ! $basePath) {
Expand Down Expand Up @@ -1105,21 +1105,21 @@ public static function removePathDotSegments($path)
}
$output = substr($output, 0, $lastSlashPos);
break;
case (substr($path, 0, 4) == '/../'):
case (0 === strpos($path, '/../')):
$path = '/' . substr($path, 4);
$lastSlashPos = strrpos($output, '/', -1);
if (false === $lastSlashPos) {
break;
}
$output = substr($output, 0, $lastSlashPos);
break;
case (substr($path, 0, 3) == '/./'):
case (0 === strpos($path, '/./')):
$path = substr($path, 2);
break;
case (substr($path, 0, 2) == './'):
case (0 === strpos($path, './')):
$path = substr($path, 2);
break;
case (substr($path, 0, 3) == '../'):
case (0 === strpos($path, '../')):
$path = substr($path, 3);
break;
default:
Expand Down

0 comments on commit 081f5fa

Please sign in to comment.