Skip to content

Commit

Permalink
Merge pull request #44 from patinthehat/v2
Browse files Browse the repository at this point in the history
Add PHP 8-only Support (v2)
  • Loading branch information
freekmurze authored Mar 31, 2021
2 parents 56fdc77 + 5853658 commit 343eb6a
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 118 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
Expand All @@ -13,3 +10,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
6 changes: 4 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.php_cs export-ignore
/.github export-ignore
/psalm.xml export-ignore
File renamed without changes.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: spatie
custom: https://spatie.be/open-source/support-us
3 changes: 3 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
23 changes: 23 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check & fix styling

on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
73 changes: 37 additions & 36 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
name: run-tests
name: Tests

on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'
push:
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
php: [8.0, 7.4, 7.3, 7.2]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest, windows-latest]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests on Ubuntu OS
if: matrix.operating-system == 'ubuntu-latest'
run: XDEBUG_MODE=coverage vendor/bin/phpunit

- name: Execute tests on Windows OS
if: matrix.operating-system == 'windows-latest'
run: vendor/bin/phpunit
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, json, libxml, mbstring
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.idea
.php_cs
.php_cs.cache
.phpunit.result.cache
build
composer.lock
coverage
docs
phpunit.xml
psalm.xml
vendor
.phpunit.result.cache
40 changes: 40 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All Notable changes to `url` will be documented in this file

## 2.0.0 - unreleased

- require PHP 8+
- drop support for PHP 7.x
- use PHP 8 syntax where possible

## 1.3.5 - 2020-11-05

- update deps
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Parse, build and manipulate URL's
# Parse, build and manipulate URLs

[![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)
![run-tests](https://github.com/spatie/url/workflows/run-tests/badge.svg)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/spatie/url/Tests?label=tests)](https://github.com/spatie/url/actions?query=workflow%3ATests+branch%3Amaster)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/url.svg?style=flat-square)](https://packagist.org/packages/spatie/url)

A simple package to deal with URL's in your applications.
A simple package to deal with URLs in your applications.

Retrieve parts of the URL:

Expand Down Expand Up @@ -69,7 +69,7 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh

You can install the package via composer:

``` bash
```bash
composer require spatie/url
```

Expand All @@ -83,17 +83,21 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen

## Testing

``` bash
```bash
composer test
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Security
## Security Vulnerabilities

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

## Postcardware

Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
}
],
"require": {
"php": "^7.2|^8.0",
"php": "^8.0",
"psr/http-message": "^1.0",
"spatie/macroable": "^1.0.1"
"spatie/macroable": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.3"
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand All @@ -34,9 +34,12 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
4 changes: 2 additions & 2 deletions src/Exceptions/InvalidArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class InvalidArgument extends InvalidArgumentException
{
public static function invalidScheme(string $url): self
public static function invalidScheme(string $url): static
{
return new static("The scheme `{$url}` isn't valid. It should be either `http` or `https`.");
}

public static function segmentZeroDoesNotExist()
public static function segmentZeroDoesNotExist(): static
{
return new static("Segment 0 doesn't exist. Segments can be retrieved by using 1-based index or a negative index.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Arr
{
public static function map(array $items, callable $callback)
public static function map(array $items, callable $callback): array
{
$keys = array_keys($items);

Expand All @@ -13,7 +13,7 @@ public static function map(array $items, callable $callback)
return array_combine($keys, $items);
}

public static function mapToAssoc(array $items, callable $callback)
public static function mapToAssoc(array $items, callable $callback): mixed
{
return array_reduce($items, function (array $assoc, $item) use ($callback) {
[$key, $value] = $callback($item);
Expand Down
27 changes: 13 additions & 14 deletions src/QueryParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

class QueryParameterBag
{
/** @var array */
protected $parameters;

public function __construct(array $parameters = [])
{
$this->parameters = $parameters;
public function __construct(
protected array $parameters = [],
) {
//
}

public static function fromString(string $query = ''): self
public static function fromString(string $query = ''): static
{
if ($query === '') {
return new static();
Expand All @@ -29,7 +27,7 @@ public static function fromString(string $query = ''): self
}));
}

public function get(string $key, $default = null)
public function get(string $key, mixed $default = null): mixed
{
return $this->parameters[$key] ?? $default;
}
Expand All @@ -39,14 +37,14 @@ public function has(string $key): bool
return array_key_exists($key, $this->parameters);
}

public function set(string $key, string $value)
public function set(string $key, string $value): self
{
$this->parameters[$key] = $value;

return $this;
}

public function unset(string $key)
public function unset(string $key): self
{
unset($this->parameters[$key]);

Expand All @@ -58,11 +56,12 @@ public function all(): array
return $this->parameters;
}

public function __toString()
public function __toString(): string
{
$keyValuePairs = Arr::map($this->parameters, function ($value, $key) {
return "{$key}=".rawurlencode($value);
});
$keyValuePairs = Arr::map(
$this->parameters,
fn ($value, $key) => "{$key}=".rawurlencode($value)
);

return implode('&', $keyValuePairs);
}
Expand Down
Loading

0 comments on commit 343eb6a

Please sign in to comment.