Commit ff43698d authored by Sebastian De Deyne's avatar Sebastian De Deyne Committed by GitHub
Browse files

Merge pull request #5 from spatie/code-review

Code review
parents 730cf0d1 c1a94469
preset: laravel
linting: true
......@@ -3,7 +3,7 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/url.svg?style=flat-square)](https://packagist.org/packages/spatie/url)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/spatie/url/master.svg?style=flat-square)](https://travis-ci.org/spatie/url)
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/xxxxxxxxx.svg?style=flat-square)](https://insight.sensiolabs.com/projects/xxxxxxxxx)
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/511cb04c-4420-4400-993d-5ba4ef55071f.svg?style=flat-square)](https://insight.sensiolabs.com/projects/511cb04c-4420-4400-993d-5ba4ef55071f)
[![Quality Score](https://img.shields.io/scrutinizer/g/spatie/url.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/url)
[![StyleCI](https://styleci.io/repos/67992655/shield)](https://styleci.io/repos/67992655)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/url.svg?style=flat-square)](https://packagist.org/packages/spatie/url)
......@@ -76,10 +76,7 @@ composer require spatie/url
## Usage
``` php
$skeleton = new Spatie\Skeleton();
echo $skeleton->echoPhrase('Hello, Spatie!');
```
There are some code examples at the top of this readme.
## Changelog
......
{
"name": "spatie/url",
"description": ":package_description",
"description": "Parse, build and manipulate URL's",
"keywords": [
"spatie",
"url"
......
......@@ -2,10 +2,17 @@
namespace Spatie\Url\Exceptions;
class InvalidArgument extends \InvalidArgumentException
use InvalidArgumentException;
class InvalidArgument extends InvalidArgumentException
{
public static function invalidScheme(string $url): self
{
return new static("The scheme `{$url}` isn't valid.");
return new static("The scheme `{$url}` isn't valid. It should be either `http` or `https`.");
}
public static function segmentZeroDoesNotExist()
{
return new static("Segment 0 doesn't exist. Segments can be retrieved by using 1-based index or a negative index.");
}
}
......@@ -38,11 +38,15 @@ class QueryParameterBag
public function set(string $key, string $value)
{
$this->parameters[$key] = $value;
return $this;
}
public function unset(string $key)
{
unset($this->parameters[$key]);
return $this;
}
public function all(): array
......
......@@ -73,7 +73,7 @@ class Url implements UriInterface
$authority = $this->getUserInfo().'@'.$authority;
}
if ($this->port) {
if ($this->port !== null) {
$authority .= ':'.$this->port;
}
......@@ -173,7 +173,7 @@ class Url implements UriInterface
$segments = $this->getSegments();
if ($index === 0) {
throw new InvalidArgument("Segment 0 doesn't exist. Segments can be retrieved by using 1-based index or a negative index.");
throw InvalidArgument::segmentZeroDoesNotExist();
}
if ($index < 0) {
......@@ -187,6 +187,7 @@ class Url implements UriInterface
public function withScheme($scheme)
{
$url = clone $this;
$url->scheme = $this->sanitizeScheme($scheme);
return $url;
......@@ -206,6 +207,7 @@ class Url implements UriInterface
public function withUserInfo($user, $password = null)
{
$url = clone $this;
$url->user = $user;
$url->password = $password;
......@@ -215,6 +217,7 @@ class Url implements UriInterface
public function withHost($host)
{
$url = clone $this;
$url->host = $host;
return $url;
......@@ -223,6 +226,7 @@ class Url implements UriInterface
public function withPort($port)
{
$url = clone $this;
$url->port = $port;
return $url;
......@@ -266,6 +270,7 @@ class Url implements UriInterface
public function withQuery($query)
{
$url = clone $this;
$url->query = QueryParameterBag::fromString($query);
return $url;
......@@ -274,6 +279,7 @@ class Url implements UriInterface
public function withFragment($fragment)
{
$url = clone $this;
$url->fragment = $fragment;
return $url;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment