Skip to content

Commit

Permalink
Laravel 9.x Compatibility (#27)
Browse files Browse the repository at this point in the history
Laravel 9 support
  • Loading branch information
laravel-shift authored Feb 14, 2022
1 parent 92ac305 commit ce8cfc4
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ updates:
interval: daily
time: "19:00"
open-pull-requests-limit: 10
- package-ecosystem: composer
directory: "/vendor-bin/dev"
schedule:
interval: daily
time: "19:00"
open-pull-requests-limit: 10
25 changes: 14 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ jobs:
- name: PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --no-interaction --verbose

- name: composer normalize
run: composer normalize --dry-run --no-interaction --verbose

- name: test coverage
run: |
./vendor/bin/phpunit --coverage-clover=coverage.xml --debug --verbose
Expand All @@ -53,9 +50,6 @@ jobs:
env:
INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}

- name: Psalm
run: ./vendor/bin/psalm --shepherd --no-progress

- name: PHPStan
run: ./vendor/bin/phpstan --no-interaction --verbose

Expand All @@ -65,7 +59,7 @@ jobs:
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
laravel: ['~5.5.0', '~5.6.0', '~5.7.0', '~5.8.0', '^6.0', '^7.0', '^8.0']
laravel: ['~5.5.0', '~5.6.0', '~5.7.0', '~5.8.0', '^6.0', '^7.0', '^8.0', '^9.0']
dependency-version: ['prefer-lowest', 'prefer-stable']
include:
- laravel: '~5.5.0'
Expand All @@ -82,6 +76,8 @@ jobs:
testbench: '^5.0'
- laravel: '^8.0'
testbench: '^6.0'
- laravel: '^9.0'
testbench: '^7.0'
exclude:
- laravel: '~5.3.0'
php: '7.2'
Expand All @@ -101,6 +97,14 @@ jobs:
php: '7.1'
- laravel: '^8.0'
php: '7.2'
- laravel: '^9.0'
php: '7.1'
- laravel: '^9.0'
php: '7.2'
- laravel: '^9.0'
php: '7.3'
- laravel: '^9.0'
php: '7.4'

steps:
- name: checkout code
Expand All @@ -116,13 +120,12 @@ jobs:
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}-v3
key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}-v4

- name: Install dependencies
run: |
composer remove 'infection/infection' 'phpunit/phpunit' 'ergebnis/composer-normalize' 'orchestra/testbench' 'orchestra/testbench' 'phpstan/phpstan' 'phpunit/phpunit' 'timacdonald/php-style' 'vimeo/psalm' --dev --no-update --no-interaction --verbose
composer require 'illuminate/support:${{ matrix.laravel }}' 'orchestra/testbench:${{ matrix.testbench }}' --no-update --no-interaction --verbose
composer update --${{ matrix.dependency-version }} --no-suggest --no-interaction --verbose
composer require 'illuminate/support:${{ matrix.laravel }}' 'orchestra/testbench:${{ matrix.testbench }}' --no-update --no-interaction --verbose --no-scripts
composer update --${{ matrix.dependency-version }} --no-suggest --no-interaction --verbose --no-scripts
- name: Check platform requirements
run: composer check-platform-reqs --verbose
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
/.php_cs.cache
/coverage
/infection.log
/vendor-bin/*/vendor
/vendor-bin/*/composer.lock
/.php-cs-fixer.cache
26 changes: 26 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->notName('**/Middleware/OptionalRequired.php')
->exclude('vendor');

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true,
'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
'native_function_invocation' => true,
'declare_strict_types' => true,
'strict_comparison' => true,
'strict_param' => true,
'explicit_string_variable' => true,
'trailing_comma_in_multiline' => true,
'array_indentation' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'no_unreachable_default_argument_value' => false,
])
->setRiskyAllowed(true)
->setFinder($finder);
8 changes: 0 additions & 8 deletions .php_cs.dist

This file was deleted.

48 changes: 25 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
{
"name": "timacdonald/has-parameters",
"description": "A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.",
"license": "MIT",
"keywords": [
"laravel",
"middleware",
"parameters",
"arguments"
],
"license": "MIT",
"authors": [
{
"name": "Tim MacDonald",
"email": "[email protected]",
"homepage": "https://timacdonald.me"
}
],
"support": {
"issues": "https://github.com/timacdonald/has-parameters/issues",
"source": "https://github.com/timacdonald/has-parameters/releases/latest",
"docs": "https://github.com/timacdonald/has-parameters/blob/master/readme.md"
},
"require": {
"php": "^7.1 || ^8.0",
"illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0 || ^7.0 || ^8.0"
"illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"illuminate/http": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.0",
"infection/infection": "^0.25",
"orchestra/testbench": "^6.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^9.0",
"timacdonald/php-style": "dev-master",
"vimeo/psalm": "^4.0"
},
"config": {
"preferred-install": "dist",
"sort-packages": true
"bamarni/composer-bin-plugin": "^1.4"
},
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
"TiMacDonald\\Middleware\\": "src"
Expand All @@ -42,30 +40,34 @@
"Tests\\": "tests/"
}
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
},
"preferred-install": "dist",
"sort-packages": true
},
"scripts": {
"bin": "echo 'bin not installed'",
"post-install-cmd": [
"@composer bin all install --ansi"
],
"post-update-cmd": [
"@composer bin all update --ansi"
],
"fix": [
"clear",
"@composer normalize",
"./vendor/bin/php-cs-fixer fix"
],
"lint": [
"clear",
"@composer normalize --dry-run",
"./vendor/bin/php-cs-fixer fix --dry-run",
"./vendor/bin/psalm --threads=8",
"./vendor/bin/phpstan analyse"
],
"test": [
"clear",
"./vendor/bin/phpunit",
"./vendor/bin/infection --threads=8"
]
},
"support": {
"issues": "https://github.com/timacdonald/has-parameters/issues",
"source": "https://github.com/timacdonald/has-parameters/releases/latest",
"docs": "https://github.com/timacdonald/has-parameters/blob/master/readme.md"
}
}
4 changes: 2 additions & 2 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"logs": {
"text": "infection.log",
"badge": {
"branch": "master"
"stryker": {
"badge": "main"
}
},
"mutators": {
Expand Down
6 changes: 2 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
parameters:
checkMissingIterableValueType: false
level: max
checkGenericClassInNonGenericObjectType: false
level: 8
paths:
- src
- tests
excludePaths:
- tests/Middleware/OptionalRequired.php
34 changes: 0 additions & 34 deletions psalm.xml

This file was deleted.

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Read more about the why in my blog post [Rethinking Laravel's middleware argumen
## Version support

- **PHP**: 7.1, 7.2, 7.3, 7.4, 8.0
- **Laravel**: 5.5, 5.6, 5.7, 5.8, 6.0, 7.0, 8.0
- **Laravel**: 5.5, 5.6, 5.7, 5.8, 6.0, 7.0, 8.0, 9.0

## Installation

Expand Down
9 changes: 6 additions & 3 deletions src/HasParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
trait HasParameters
{
/**
* @param mixed $arguments
* @param array $arguments
*/
public static function with($arguments): string
{
Expand All @@ -23,7 +23,10 @@ public static function with($arguments): string

self::validateArgumentMapIsAnAssociativeArray($arguments);

$aliases = new Collection(static::parameterAliasMap());
$aliases = new Collection(
/** @phpstan-ignore-next-line */
static::parameterAliasMap()
);

if ($aliases->isNotEmpty()) {
self::validateAliasesReferenceParameters($parameters, $aliases);
Expand All @@ -45,7 +48,7 @@ public static function with($arguments): string
}

/**
* @param mixed $arguments
* @param array $arguments
*/
public static function in($arguments): string
{
Expand Down
6 changes: 3 additions & 3 deletions tests/HasParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Orchestra\Testbench\TestCase;
use const PHP_MAJOR_VERSION;
use Tests\Middleware\Aliased;
use Tests\Middleware\Basic;
use Tests\Middleware\Optional;
Expand All @@ -19,6 +18,7 @@
use Tests\Middleware\Variadic;
use TiMacDonald\Middleware\HasParameters;
use TypeError;
use const PHP_MAJOR_VERSION;

/**
* @small
Expand Down Expand Up @@ -300,7 +300,7 @@ public function testParameterAliasesDontConflictWithOtherAliasNames(): void
$this->expectException(TypeError::class);
$this->expectExceptionMessage('Two provided aliases cannot point to the same parameter.');

$middleware = new class() {
$middleware = new class () {
use HasParameters;

public function handle(Request $request, Closure $next, string $original, string $anotherOne): void
Expand Down Expand Up @@ -329,7 +329,7 @@ public function testAliasesReferenceActualParameters(): void
$this->expectException(TypeError::class);
$this->expectExceptionMessage('Aliases must reference existing parameters.');

$middleware = new class() {
$middleware = new class () {
use HasParameters;

public function handle(Request $request, Closure $next, string $original): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Middleware/OptionalRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Closure;
use Illuminate\Http\Request;
use const PHP_MAJOR_VERSION;
use TiMacDonald\Middleware\HasParameters;
use const PHP_MAJOR_VERSION;

// Cannot have optional parameter before required parameter in PHP >=8.0.
if (PHP_MAJOR_VERSION < 8) {
Expand Down
14 changes: 14 additions & 0 deletions vendor-bin/dev/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"require": {
"friendsofphp/php-cs-fixer": "^3.6",
"infection/infection": "^0.26.4",
"orchestra/testbench": "^7.0",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^9.5"
},
"config": {
"allow-plugins": {
"infection/extension-installer": true
}
}
}

0 comments on commit ce8cfc4

Please sign in to comment.