Skip to content

Commit 85c3ac2

Browse files
author
Philipp Kübler
committed
use new linter rules
1 parent 571fcaa commit 85c3ac2

13 files changed

+22
-34
lines changed

phpcs.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<file>src</file>
1010
<file>tests</file>
1111

12+
<exclude-pattern>*/tests/resources/*.blade.php</exclude-pattern>
1213

1314
<!-- Generic -->
1415
<rule ref="Generic.Files.LineLength">

src/Middlewares/RoleMiddleware.php

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class RoleMiddleware
99
{
10-
1110
/**
1211
* Handle an incoming request.
1312
*
@@ -31,5 +30,4 @@ public function handle(Request $request, Closure $next, string $roles)
3130

3231
return $next($request);
3332
}
34-
3533
}

src/PermissionServiceProvider.php

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class PermissionServiceProvider extends ServiceProvider
99
{
10-
1110
/**
1211
* Bootstrap the application services.
1312
*/
@@ -84,5 +83,4 @@ protected function registerBladeExtensions(): void
8483
});
8584
});
8685
}
87-
8886
}

src/Traits/HasPermissions.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
trait HasPermissions
88
{
9-
109
/**
1110
* Check if model has all permissions
1211
*
13-
* @param array|string ...$permissions
12+
* @param string[]|string ...$permissions
1413
* @return bool
1514
*/
1615
public function hasPermissionTo(...$permissions): bool
@@ -35,7 +34,7 @@ public function hasPermissionTo(...$permissions): bool
3534
/**
3635
* Check if model has all permissions
3736
*
38-
* @param array|string ...$permissions
37+
* @param string[]|string ...$permissions
3938
* @return bool
4039
*/
4140
public function hasPermission(...$permissions): bool
@@ -46,7 +45,7 @@ public function hasPermission(...$permissions): bool
4645
/**
4746
* Check if model has any permissions
4847
*
49-
* @param array|string ...$permissions
48+
* @param string[]|string ...$permissions
5049
* @return bool
5150
*/
5251
public function hasAnyPermission(...$permissions): bool
@@ -87,7 +86,7 @@ public function getAllPermissions(): Collection
8786
* Match ruleset to permission
8887
*
8988
* @param \Illuminate\Support\Collection $rules Ruleset
90-
* @param array $permission
89+
* @param string[] $permission
9190
* @return bool
9291
*/
9392
public function matchPermission(Collection $rules, array $permission): bool
@@ -111,8 +110,8 @@ public function matchPermission(Collection $rules, array $permission): bool
111110
/**
112111
* Match one rule to permission
113112
*
114-
* @param array $rule
115-
* @param array $permission
113+
* @param string[] $rule
114+
* @param string[] $permission
116115
* @return bool
117116
*/
118117
public function matchRuleToPermission(array $rule, array $permission): bool
@@ -146,5 +145,4 @@ public function matchRuleToPermission(array $rule, array $permission): bool
146145

147146
return $countPermissionParts === $countRuleParts;
148147
}
149-
150148
}

src/Traits/HasRoles.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
trait HasRoles
66
{
7-
87
use HasPermissions;
98

109
/**
@@ -48,5 +47,4 @@ public function getRoleName(): ?string
4847
{
4948
return $this->{config('permission.column_name')};
5049
}
51-
5250
}

tests/BladeTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class BladeTest extends TestCase
88
{
9-
109
public function testPermission(): void
1110
{
1211
$this->user->assignRole('admin');
@@ -71,7 +70,7 @@ protected function setUp(): void
7170
* return compiled blade views
7271
*
7372
* @param string $view view name
74-
* @param array $parameters vars can used in the view
73+
* @param string[] $parameters vars can used in the view
7574
*/
7675
protected function renderView(string $view, array $parameters): string
7776
{
@@ -83,5 +82,4 @@ protected function renderView(string $view, array $parameters): string
8382

8483
return trim((string) $view);
8584
}
86-
8785
}

tests/MatchPermissionTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
class MatchPermissionTest extends TestCase
66
{
7-
87
public function testNoRules(): void
98
{
109
$rules = collect([]);
@@ -61,5 +60,4 @@ protected function setUp(): void
6160
];
6261
$this->user = User::create(['email' => '[email protected]']);
6362
}
64-
6563
}

tests/MatchRuleToPermissionTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
class MatchRuleToPermissionTest extends TestCase
66
{
7-
87
public function testDirectRule(): void
98
{
109
$rule = [
@@ -96,5 +95,4 @@ protected function setUp(): void
9695
];
9796
$this->user = User::create(['email' => '[email protected]']);
9897
}
99-
10098
}

tests/MiddlewareTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class MiddlewareTest extends TestCase
1212
{
13-
1413
public function testGustCannotAccessProtectedRoute(): void
1514
{
1615
$this->assertEquals($this->runMiddleware($this->roleMiddleware, 'admin'), 403);
@@ -53,12 +52,11 @@ protected function setUp(): void
5352
protected function runMiddleware(RoleMiddleware $middleware, string $parameter): int
5453
{
5554
try {
56-
return $middleware->handle(new Request, static function () {
57-
return (new Response)->SetContent('<html></html>');
55+
return $middleware->handle(new Request(), static function () {
56+
return (new Response())->SetContent('<html></html>');
5857
}, $parameter)->status();
5958
} catch (HttpException $e) {
6059
return $e->getStatusCode();
6160
}
6261
}
63-
6462
}

tests/PermissionTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/** @SuppressWarnings(PHPMD.TooManyPublicMethods) */
66
class PermissionTest extends TestCase
77
{
8-
98
public function testGetPermissions(): void
109
{
1110
$this->user->assignRole('user');
@@ -130,5 +129,4 @@ protected function setUp(): void
130129

131130
$this->user = User::create(['email' => '[email protected]']);
132131
}
133-
134132
}

tests/RoleTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
class RoleTest extends TestCase
66
{
7-
87
public function testAssignExistentRole(): void
98
{
109
$this->user->assignRole('admin');
@@ -60,5 +59,4 @@ protected function setUp(): void
6059

6160
$this->user = User::create(['email' => '[email protected]']);
6261
}
63-
6462
}

tests/TestCase.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
class TestCase extends OrchestraTestCase
1111
{
12-
1312
/**
1413
* Setup the test environment.
1514
*
@@ -29,6 +28,7 @@ protected function setUp(): void
2928
* @return array
3029
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3130
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
31+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
3232
*/
3333
protected function getPackageProviders($app): array
3434
{
@@ -40,6 +40,7 @@ protected function getPackageProviders($app): array
4040
*
4141
* @param \Illuminate\Foundation\Application $app
4242
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification
43+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
4344
*/
4445
protected function getEnvironmentSetUp($app): void
4546
{
@@ -71,5 +72,4 @@ protected function setUpDatabase(Application $app): void
7172
$table->string('role')->nullable();
7273
});
7374
}
74-
7575
}

tests/User.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@
1111

1212
class User extends Model implements AuthorizableContract, AuthenticatableContract
1313
{
14-
1514
use HasRoles;
1615
use Authorizable;
1716
use Authenticatable;
1817

18+
/**
19+
* @var bool
20+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
21+
*/
1922
public $timestamps = false;
2023

2124
/**
2225
* The attributes that are mass assignable.
2326
*
24-
* @var array
27+
* @var string[]
28+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
2529
*/
2630
protected $fillable = ['email'];
2731

32+
/**
33+
* @var string
34+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
35+
*/
2836
protected $table = 'users';
29-
3037
}

0 commit comments

Comments
 (0)