Skip to content

Commit

Permalink
Add Laravel v9.* support (#12)
Browse files Browse the repository at this point in the history
* Add Laravel v9.* support

* Apply fixes from StyleCI (#11)

* Apply fixes from StyleCI

Co-authored-by: hkp22 <hkp22@users.noreply.github.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
3 people authored Feb 11, 2022
1 parent e5bd81d commit caee958
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.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.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,39 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [7.2, 7.3, 7.4, 8.0]
laravel: [6.*, 7.*, 8.*]
php: [7.2, 7.3, 7.4, 8.0, 8.1]
laravel: [6.*, 7.*, 8.*, 9.*]
stability: [prefer-lowest, prefer-stable]
exclude:
- laravel: 6.*
stability: prefer-lowest
- laravel: 7.*
stability: prefer-lowest
- laravel: 8.*
stability: prefer-lowest
- laravel: 9.*
stability: prefer-lowest
- laravel: 6.*
php: 8.1
- laravel: 7.*
php: 8.1
- laravel: 8.*
php: 7.2
- laravel: 9.*
php: 7.2
- laravel: 9.*
php: 7.3
- laravel: 9.*
php: 7.4
include:
- laravel: 6.*
testbench: 4.*
- laravel: 7.*
testbench: 5.*
- laravel: 8.*
testbench: 6.*
- laravel: 9.*
testbench: 7.*

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

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.php_cs
.php_cs.cache
.php_cs.dist.php.cache
.phpunit.result.cache
build
composer.lock
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"php":"8.1.2","version":"3.6.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":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":"one"}}},"hashes":{"src\/Exceptions\/BannableTraitNotUsed.php":3934737596,"src\/BannableServiceProvider.php":2685787619,"src\/Models\/Ban.php":3503919105,"src\/Events\/ModelWasUnbanned.php":1811445519,"src\/Events\/ModelWasBanned.php":3761930836,"src\/Observers\/BanObserver.php":3401375689,"src\/Scopes\/BannedModelScope.php":1099366713,"src\/Traits\/HasBannedModelScope.php":80843900,"src\/Traits\/Bannable.php":1075795798,"src\/Middleware\/ForbidBannedUser.php":3496856278,"tests\/Unit\/BanExceptionTest.php":1451565077,"tests\/Unit\/BanObserverTest.php":307464778,"tests\/Unit\/BanModelTest.php":3713178039,"tests\/Unit\/BannedScopeTest.php":3252523178,"tests\/Unit\/ModelUnbannedEventTest.php":1858581101,"tests\/Unit\/ModelBannedEventTest.php":171815,"tests\/Unit\/BannableTest.php":3695110949,"tests\/Unit\/BanMiddlewareTest.php":2254635710,"tests\/TestCase.php":1116165231,"tests\/database\/factories\/BanFactory.php":934324543,"tests\/database\/factories\/UserFactory.php":868474299,"tests\/database\/migrations\/2018_06_25_000000__create_user_table.php":2535378798,"tests\/Stubs\/Models\/UserModelWithDisabledBannedScope.php":1195852277,"tests\/Stubs\/Models\/User.php":3824946933,"tests\/Stubs\/Models\/UserWithoutBannableTrait.php":2245443852}}
17 changes: 7 additions & 10 deletions .php_cs.dist → .php_cs.dist.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__.'/src',
__DIR__.'/tests',
])
->name('*.php')
->notName('*.blade.php')
->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 @@ -31,7 +28,7 @@
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method',
'method' => 'one',
],
],
'method_argument_space' => [
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
],
"require": {
"php": ">=7.0",
"illuminate/database": "5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0",
"illuminate/events": "5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0",
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0"
"illuminate/database": "^6.20.27|^7.0|^8.0|^9.0",
"illuminate/events": "^6.0|^7.0|^8.0|^9.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0"
},
"autoload": {
"psr-4": {
"Qirolab\\Laravel\\Bannable\\": "src"
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "~3.5.0|~3.6.0|~3.7.0|~3.8.0|^4.0|^5.0|^6.0",
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0",
"phpunit/phpunit": "^7.5|^8.0|^9.0",
"vimeo/psalm": "^4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/BannableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ protected function loadMigrations()
*/
protected function registerObservers()
{
$this->app->make(Ban::class)->observe(new BanObserver);
$this->app->make(Ban::class)->observe(new BanObserver());
}
}
4 changes: 2 additions & 2 deletions src/Events/ModelWasBanned.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ModelWasBanned implements ShouldQueue
public $ban;

/**
* @param Model $bannable
* @param Ban $ban
* @param Model $bannable
* @param Ban $ban
*/
public function __construct(Model $bannable, Ban $ban)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Events/ModelWasUnbanned.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ModelWasUnbanned implements ShouldQueue
public $model;

/**
* @param Model $bannable
* @param Model $bannable
*/
public function __construct(Model $bannable)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Middleware/ForbidBannedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class ForbidBannedUser
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*
* @throws \Exception
*/
public function handle($request, Closure $next)
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Ban.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Ban extends Model
/**
* Expired timestamp mutator.
*
* @param \Carbon\Carbon|string $value
* @param \Carbon\Carbon|string $value
* @return void
*/
public function setExpiredAtAttribute($value)
Expand Down Expand Up @@ -87,8 +87,8 @@ public static function deleteExpired()
/**
* Scope a query to only include models by owner.
*
* @param Builder $query
* @param Model $bannable
* @param Builder $query
* @param Model $bannable
* @return Builder
*/
public function scopeWhereBannable(Builder $query, Model $bannable)
Expand Down
12 changes: 6 additions & 6 deletions src/Scopes/BannedModelScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class BannedModelScope implements Scope
/**
* Apply the scope to a given Eloquent query builder.
*
* @param Builder $builder
* @param Model $model
* @param Builder $builder
* @param Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
Expand All @@ -38,7 +38,7 @@ public function apply(Builder $builder, Model $model)
/**
* Extend the query builder with the needed functions.
*
* @param Builder $builder
* @param Builder $builder
* @return void
*/
public function extend(Builder $builder)
Expand All @@ -53,7 +53,7 @@ public function extend(Builder $builder)
/**
* Add the `withBanned` extension to the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
protected function scopeWithBanned(Builder $builder)
Expand All @@ -66,7 +66,7 @@ protected function scopeWithBanned(Builder $builder)
/**
* Add the `withoutBanned` extension to the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
protected function scopeWithoutBanned(Builder $builder)
Expand All @@ -79,7 +79,7 @@ protected function scopeWithoutBanned(Builder $builder)
/**
* Add the `onlyBanned` extension to the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
protected function scopeOnlyBanned(Builder $builder)
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Bannable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function bans()
/**
* Ban model.
*
* @param null|array $attributes
* @param null|array $attributes
* @return Ban
*/
public function ban(array $attributes = [])
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HasBannedModelScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ trait HasBannedModelScope
*/
public static function bootHasBannedModelScope()
{
static::addGlobalScope(new BannedModelScope);
static::addGlobalScope(new BannedModelScope());
}
}
8 changes: 4 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function destroyPackageMigrations()
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function getEnvironmentSetUp($app)
Expand All @@ -65,7 +65,7 @@ protected function getEnvironmentSetUp($app)
/**
* Load package service provider.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
Expand Down Expand Up @@ -117,13 +117,13 @@ public function factory($class, $attributes = [], $amount = null)
$resource = [];

for ($i = 0; $i < $amount; $i++) {
$resource[] = (new $class)->forceCreate($attributes);
$resource[] = (new $class())->forceCreate($attributes);
}

return new Collection($resource);
}

return (new $class)->forceCreate($attributes);
return (new $class())->forceCreate($attributes);
}

public function createUser($class = null, $attributes = [], $amount = null)
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/ModelBannedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Qirolab\Tests\Laravel\Bannable\Unit;

use Illuminate\Foundation\Testing\Concerns\MocksApplicationServices;
use Qirolab\Laravel\Bannable\Events\ModelWasBanned;
use Qirolab\Tests\Laravel\Bannable\Stubs\Models\User;
use Qirolab\Tests\Laravel\Bannable\TestCase;

class ModelBannedEventTest extends TestCase
{
use MocksApplicationServices;

/** @test */
public function it_can_fire_event_on_helper_call()
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/ModelUnbannedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Qirolab\Tests\Laravel\Bannable\Unit;

use Illuminate\Foundation\Testing\Concerns\MocksApplicationServices;
use Qirolab\Laravel\Bannable\Events\ModelWasUnbanned;
use Qirolab\Tests\Laravel\Bannable\TestCase;

class ModelUnbannedEventTest extends TestCase
{
use MocksApplicationServices;

/** @test */
public function it_can_fire_event_on_helper_call()
{
Expand Down

0 comments on commit caee958

Please sign in to comment.