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

Commit

Permalink
Merge 765fcd0 into bb833f8
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed May 25, 2018
2 parents bb833f8 + 765fcd0 commit 56e4e8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
42 changes: 19 additions & 23 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function __construct($uri = '')
));
}

if (! empty($uri)) {
if ('' !== $uri) {
$this->parseUri($uri);
}
}
Expand Down Expand Up @@ -147,12 +147,12 @@ public function getScheme()
*/
public function getAuthority()
{
if (empty($this->host)) {
if ('' === $this->host) {
return '';
}

$authority = $this->host;
if (! empty($this->userInfo)) {
if ('' !== $this->userInfo) {
$authority = $this->userInfo . '@' . $authority;
}

Expand Down Expand Up @@ -476,27 +476,26 @@ private static function createUriString($scheme, $authority, $path, $query, $fra
{
$uri = '';

if (! empty($scheme)) {
if ('' !== $scheme) {
$uri .= sprintf('%s:', $scheme);
}

if (! empty($authority)) {
if ('' !== $authority) {
$uri .= '//' . $authority;
}

if ($path) {
if (empty($path) || '/' !== substr($path, 0, 1)) {
$path = '/' . $path;
}

$uri .= $path;
if ('' !== $path && '/' !== substr($path, 0, 1)) {
$path = '/' . $path;
}

if ($query) {
$uri .= $path;


if ('' !== $query) {
$uri .= sprintf('?%s', $query);
}

if ($fragment) {
if ('' !== $fragment) {
$uri .= sprintf('#%s', $fragment);
}

Expand All @@ -513,14 +512,11 @@ private static function createUriString($scheme, $authority, $path, $query, $fra
*/
private function isNonStandardPort($scheme, $host, $port)
{
if (! $scheme) {
if ($host && ! $port) {
return false;
}
return true;
if ('' === $scheme) {
return '' === $host || null !== $port;
}

if (! $host || ! $port) {
if ('' === $host || null === $port) {
return false;
}

Expand All @@ -539,7 +535,7 @@ private function filterScheme($scheme)
$scheme = strtolower($scheme);
$scheme = preg_replace('#:(//)?$#', '', $scheme);

if (empty($scheme)) {
if ('' === $scheme) {
return '';
}

Expand Down Expand Up @@ -585,7 +581,7 @@ private function filterPath($path)
$path
);

if (empty($path)) {
if ('' === $path) {
// No path
return $path;
}
Expand All @@ -609,7 +605,7 @@ private function filterPath($path)
*/
private function filterQuery($query)
{
if (! empty($query) && strpos($query, '?') === 0) {
if ('' !== $query && strpos($query, '?') === 0) {
$query = substr($query, 1);
}

Expand Down Expand Up @@ -653,7 +649,7 @@ private function splitQueryValue($value)
*/
private function filterFragment($fragment)
{
if (! empty($fragment) && strpos($fragment, '#') === 0) {
if ('' !== $fragment && strpos($fragment, '#') === 0) {
$fragment = '%23' . substr($fragment, 1);
}

Expand Down
8 changes: 8 additions & 0 deletions test/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,12 @@ public function testHostIsLowercaseWhenIsSetViwWithHost()
$uri = (new Uri())->withHost('NEW-HOST.COM');
$this->assertSame('new-host.com', $uri->getHost());
}


public function testUriDistinguishZeroFromEmptyString()
{
$expected = 'https://0:0@0:1/0?0#0';
$uri = new Uri($expected);
$this->assertSame($expected, (string) $uri);
}
}

0 comments on commit 56e4e8a

Please sign in to comment.