Skip to content

Commit

Permalink
Merge pull request #81 from mostafamaklad/v1.10
Browse files Browse the repository at this point in the history
fix test  coverage
  • Loading branch information
mostafamaklad committed Nov 16, 2018
2 parents f9aee90 + ab04e3a commit 027fcfa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All Notable changes to `laravel-permission-mongodb` will be documented in this file.

## 1.10.1 - 2018-09-16

### Fixed
- Fix test coverage

## 1.10.0 - 2018-09-15

### Added
Expand Down
11 changes: 11 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,19 @@ public function getUserNotLoggedINMessage(): string
return 'User is not logged in.';
}

/**
* @return bool
*/
public function isNotLumen(): bool
{
return ! (stripos(app()->version(), 'lumen') !== false);
}

/**
* @return bool
*/
public function checkVersion(): bool
{
return ($this->isNotLumen() && app()::VERSION < '5.4');
}
}
6 changes: 1 addition & 5 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ public static function create(array $attributes = [])
throw new PermissionAlreadyExists($helpers->getPermissionAlreadyExistsMessage($name, $guardName));
}

if ($helpers->isNotLumen() && app()::VERSION < '5.4') {
return parent::create($attributes);
}

return static::query()->create($attributes);
return $helpers->checkVersion() ? parent::create($attributes) : static::query()->create($attributes);
}

/**
Expand Down
28 changes: 12 additions & 16 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,15 @@ public function __construct(array $attributes = [])
public static function create(array $attributes = [])
{
$attributes['guard_name'] = $attributes['guard_name'] ?? (new Guard())->getDefaultName(static::class);
$helpers = new Helpers();
$helpers = new Helpers();

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

if ($helpers->isNotLumen() && app()::VERSION < '5.4') {
return parent::create($attributes);
}

return static::query()->create($attributes);
return $helpers->checkVersion() ? parent::create($attributes) : static::query()->create($attributes);
}

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

$role = static::where('name', $name)
->where('guard_name', $guardName)
->first();
->where('guard_name', $guardName)
->first();

if (! $role) {
if (!$role) {
$role = static::create(['name' => $name, 'guard_name' => $guardName]);
}

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

$role = static::where('name', $name)
->where('guard_name', $guardName)
->first();
->where('guard_name', $guardName)
->first();

if (! $role) {
if (!$role) {
$helpers = new Helpers();
throw new RoleDoesNotExist($helpers->getRoleDoesNotExistMessage($name, $guardName));
}
Expand All @@ -137,9 +133,9 @@ public function hasPermissionTo($permission): bool
$permission = $this->getPermissionClass()->findByName($permission, $this->getDefaultGuardName());
}

if (! $this->getGuardNames()->contains($permission->guard_name)) {
if (!$this->getGuardNames()->contains($permission->guard_name)) {
$expected = $this->getGuardNames();
$given = $permission->guard_name;
$given = $permission->guard_name;

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

0 comments on commit 027fcfa

Please sign in to comment.