Skip to content

Commit

Permalink
code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Sep 26, 2016
1 parent 730cf0d commit c1a9446
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
preset: laravel

linting: true
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spatie/url",
"description": ":package_description",
"description": "Parse, build and manipulate URL's",
"keywords": [
"spatie",
"url"
Expand Down
Empty file removed config/.gitkeep
Empty file.
11 changes: 9 additions & 2 deletions src/Exceptions/InvalidArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
4 changes: 4 additions & 0 deletions src/QueryParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ public function has(string $key): bool
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
Expand Down
10 changes: 8 additions & 2 deletions src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getAuthority()
$authority = $this->getUserInfo().'@'.$authority;
}

if ($this->port) {
if ($this->port !== null) {
$authority .= ':'.$this->port;
}

Expand Down Expand Up @@ -173,7 +173,7 @@ public function getSegment(int $index, $default = null)
$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) {
Expand All @@ -187,6 +187,7 @@ public function getSegment(int $index, $default = null)
public function withScheme($scheme)
{
$url = clone $this;

$url->scheme = $this->sanitizeScheme($scheme);

return $url;
Expand All @@ -206,6 +207,7 @@ protected function sanitizeScheme(string $scheme): string
public function withUserInfo($user, $password = null)
{
$url = clone $this;

$url->user = $user;
$url->password = $password;

Expand All @@ -215,6 +217,7 @@ public function withUserInfo($user, $password = null)
public function withHost($host)
{
$url = clone $this;

$url->host = $host;

return $url;
Expand All @@ -223,6 +226,7 @@ public function withHost($host)
public function withPort($port)
{
$url = clone $this;

$url->port = $port;

return $url;
Expand Down Expand Up @@ -266,6 +270,7 @@ public function withBasename(string $basename)
public function withQuery($query)
{
$url = clone $this;

$url->query = QueryParameterBag::fromString($query);

return $url;
Expand All @@ -274,6 +279,7 @@ public function withQuery($query)
public function withFragment($fragment)
{
$url = clone $this;

$url->fragment = $fragment;

return $url;
Expand Down

0 comments on commit c1a9446

Please sign in to comment.