Skip to content

Commit

Permalink
Merge pull request #3 from agilepixels/feature/support-laravel-9
Browse files Browse the repository at this point in the history
Add support for Laravel 9
  • Loading branch information
lexdewilligen committed Jan 21, 2023
2 parents 756d2c5 + 6af4c13 commit 5ed1e46
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist --allow-risky=yes
args: --config=.php_cs.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.0]
laravel: [6.*, 7.*, 8.*]
dependency-version: [prefer-lowest, prefer-stable]
php: [8.2, 8.1, 8.0]
laravel: [9.*]
dependency-version: [prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 6.*
testbench: 4.*
- laravel: 9.*
testbench: 7.*

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

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.idea
vendor
.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
composer.lock
coverage
11 changes: 6 additions & 5 deletions .php_cs.dist → .php_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
Expand All @@ -32,6 +32,7 @@
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
]
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name" : "agilepixels/laravel-resource-abilities",
"description" : "Add abilities to Laravel API resources",
"keywords" : [
"agilepixels",
"laravel-resource-abilities"
"laravel",
"php"
],
"homepage" : "https://github.com/agilepixels/laravel-resource-abilities",
"license" : "MIT",
Expand All @@ -16,12 +16,12 @@
}
],
"require" : {
"php" : "^8.0",
"illuminate/database" : "~5.8.0|^6.0|^7.0|^8.0",
"illuminate/routing" : "~5.8.0|^6.0|^7.0|^8.0"
"php" : "^8.0|^8.1|^8.2",
"illuminate/database" : "^9.0",
"illuminate/routing" : "^9.0"
},
"require-dev" : {
"orchestra/testbench" : "~3.8.0|^4.0|^5.0|^6.0",
"orchestra/testbench" : "^7.0",
"phpunit/phpunit" : "^8.0|^9.0"
},
"autoload" : {
Expand Down
3 changes: 1 addition & 2 deletions src/AbilityTypes/AbilityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use AgilePixels\ResourceAbilities\Serializers\Serializer;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;

abstract class AbilityType
{
Expand Down Expand Up @@ -52,7 +51,7 @@ protected function resolveSerializer(): Serializer
? config('resource-abilities.serializer')
: $this->serializer;

return new $serializer;
return new $serializer();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/AbilityTypes/GateAbilityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function make(string $ability, Model | string $model): GateAbility

public function getAbilities(array $abilities, bool $withAllAbilities): array
{
if (!in_array($this->ability, $abilities, true) && ! $withAllAbilities) {
if (! in_array($this->ability, $abilities, true) && ! $withAllAbilities) {
return [];
}

Expand Down
5 changes: 5 additions & 0 deletions src/AbilityTypes/PolicyAbilityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public function getAbilities(array $abilities, bool $withAllAbilities): array
{
return collect($this->abilities)

/**
* Filter out helper methods
*/
->reject(fn (string $ability) => in_array($ability, ['denyWithStatus', 'denyAsNotFound']))

/**
* Filter out the non-specified abilities
*/
Expand Down
1 change: 0 additions & 1 deletion src/Builder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace AgilePixels\ResourceAbilities;

use Illuminate\Database\Eloquent\Builder as BaseBuilder;
Expand Down
1 change: 0 additions & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace AgilePixels\ResourceAbilities;

use Illuminate\Database\Eloquent\Collection as BaseCollection;
Expand Down
3 changes: 2 additions & 1 deletion tests/Fakes/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class UserResource extends JsonResource
{
use ProcessesAbilities, HasRelationships;
use ProcessesAbilities;
use HasRelationships;

public function toArray($request): array
{
Expand Down
20 changes: 12 additions & 8 deletions tests/HasRelationshipsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ protected function setUp(): void
/** @test */
public function it_will_drop_a_to_one_relation_when_not_loaded()
{
$testResource = new class(null) extends JsonResource {
use ProcessesAbilities, HasRelationships;
$testResource = new class (null) extends JsonResource {
use ProcessesAbilities;
use HasRelationships;

public function toArray($request)
{
Expand All @@ -56,8 +57,9 @@ public function toArray($request)
/** @test */
public function it_will_add_a_to_one_relation_when_loaded()
{
$testResource = new class(null) extends JsonResource {
use ProcessesAbilities, HasRelationships;
$testResource = new class (null) extends JsonResource {
use ProcessesAbilities;
use HasRelationships;

public function toArray($request)
{
Expand All @@ -84,8 +86,9 @@ public function toArray($request)
/** @test */
public function it_will_drop_a_to_many_relation_when_not_loaded()
{
$testResource = new class(null) extends JsonResource {
use ProcessesAbilities, HasRelationships;
$testResource = new class (null) extends JsonResource {
use ProcessesAbilities;
use HasRelationships;

public function toArray($request)
{
Expand All @@ -105,8 +108,9 @@ public function toArray($request)
/** @test */
public function it_will_add_a_to_many_relation_when_loaded()
{
$testResource = new class(null) extends JsonResource {
use ProcessesAbilities, HasRelationships;
$testResource = new class (null) extends JsonResource {
use ProcessesAbilities;
use HasRelationships;

public function toArray($request)
{
Expand Down
Loading

0 comments on commit 5ed1e46

Please sign in to comment.