Skip to content

Commit d2f56ef

Browse files
committed
fix coverage
1 parent ecda13a commit d2f56ef

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/Helpers.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,19 @@ public function getUserNotLoggedINMessage(): string
117117
return 'User is not logged in.';
118118
}
119119

120+
/**
121+
* @return bool
122+
*/
120123
public function isNotLumen(): bool
121124
{
122125
return ! (stripos(app()->version(), 'lumen') !== false);
123126
}
127+
128+
/**
129+
* @return bool
130+
*/
131+
public function checkVersion(): bool
132+
{
133+
return ($this->isNotLumen() && app()::VERSION < '5.4');
134+
}
124135
}

src/Models/Permission.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ public static function create(array $attributes = [])
6767
throw new PermissionAlreadyExists($helpers->getPermissionAlreadyExistsMessage($name, $guardName));
6868
}
6969

70-
if ($helpers->isNotLumen() && app()::VERSION < '5.4') {
71-
return parent::create($attributes);
72-
}
73-
74-
return static::query()->create($attributes);
70+
return $helpers->checkVersion() ? parent::create($attributes) : static::query()->create($attributes);
7571
}
7672

7773
/**

src/Models/Role.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,15 @@ public function __construct(array $attributes = [])
5555
public static function create(array $attributes = [])
5656
{
5757
$attributes['guard_name'] = $attributes['guard_name'] ?? (new Guard())->getDefaultName(static::class);
58-
$helpers = new Helpers();
58+
$helpers = new Helpers();
5959

6060
if (static::where('name', $attributes['name'])->where('guard_name', $attributes['guard_name'])->first()) {
61-
$name = (string) $attributes['name'];
62-
$guardName = (string) $attributes['guard_name'];
61+
$name = (string)$attributes['name'];
62+
$guardName = (string)$attributes['guard_name'];
6363
throw new RoleAlreadyExists($helpers->getRoleAlreadyExistsMessage($name, $guardName));
6464
}
6565

66-
if ($helpers->isNotLumen() && app()::VERSION < '5.4') {
67-
return parent::create($attributes);
68-
}
69-
70-
return static::query()->create($attributes);
66+
return $helpers->checkVersion() ? parent::create($attributes) : static::query()->create($attributes);
7167
}
7268

7369
/**
@@ -85,10 +81,10 @@ public static function findOrCreate(string $name, $guardName = null): RoleInterf
8581
$guardName = $guardName ?? (new Guard())->getDefaultName(static::class);
8682

8783
$role = static::where('name', $name)
88-
->where('guard_name', $guardName)
89-
->first();
84+
->where('guard_name', $guardName)
85+
->first();
9086

91-
if (! $role) {
87+
if (!$role) {
9288
$role = static::create(['name' => $name, 'guard_name' => $guardName]);
9389
}
9490

@@ -110,10 +106,10 @@ public static function findByName(string $name, $guardName = null): RoleInterfac
110106
$guardName = $guardName ?? (new Guard())->getDefaultName(static::class);
111107

112108
$role = static::where('name', $name)
113-
->where('guard_name', $guardName)
114-
->first();
109+
->where('guard_name', $guardName)
110+
->first();
115111

116-
if (! $role) {
112+
if (!$role) {
117113
$helpers = new Helpers();
118114
throw new RoleDoesNotExist($helpers->getRoleDoesNotExistMessage($name, $guardName));
119115
}
@@ -137,9 +133,9 @@ public function hasPermissionTo($permission): bool
137133
$permission = $this->getPermissionClass()->findByName($permission, $this->getDefaultGuardName());
138134
}
139135

140-
if (! $this->getGuardNames()->contains($permission->guard_name)) {
136+
if (!$this->getGuardNames()->contains($permission->guard_name)) {
141137
$expected = $this->getGuardNames();
142-
$given = $permission->guard_name;
138+
$given = $permission->guard_name;
143139

144140
throw new GuardDoesNotMatch($this->helpers->getGuardDoesNotMatchMessage($expected, $given));
145141
}

0 commit comments

Comments
 (0)