Skip to content

Commit

Permalink
fix php code sniffer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
makladuxbert committed Sep 6, 2017
1 parent 24cb378 commit fd889db
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 40 deletions.
12 changes: 4 additions & 8 deletions src/Exceptions/GuardDoesNotMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

use InvalidArgumentException;
use Illuminate\Support\Collection;
use Maklad\Permission\Helpers;

class GuardDoesNotMatch extends InvalidArgumentException
{
public static function create(string $givenGuard, Collection $expectedGuards)
{
$message = new static("The given role or permission should use guard `{$expectedGuards->implode(', ')}` instead of `{$givenGuard}`.");

if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
$expected = $expectedGuards->implode(', ');
$message = "The given role or permission should use guard `{$expected}` instead of `{$givenGuard}`.";
return new static(Helpers::logAlertMessage($message));
}
}
10 changes: 3 additions & 7 deletions src/Exceptions/PermissionAlreadyExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
namespace Maklad\Permission\Exceptions;

use InvalidArgumentException;
use Maklad\Permission\Helpers;

class PermissionAlreadyExists extends InvalidArgumentException
{
public static function create(string $permissionName, string $guardName)
{
$message = new static("A permission `{$permissionName}` already exists for guard `{$guardName}`.");
$message = "A permission `{$permissionName}` already exists for guard `{$guardName}`.";

if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
return new static(Helpers::logAlertMessage($message));
}
}
10 changes: 3 additions & 7 deletions src/Exceptions/PermissionDoesNotExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
namespace Maklad\Permission\Exceptions;

use InvalidArgumentException;
use Maklad\Permission\Helpers;

class PermissionDoesNotExist extends InvalidArgumentException
{
public static function create(string $permissionName, string $guardName = '')
{
$message = new static("There is no permission named `{$permissionName}` for guard `{$guardName}`.");
$message = "There is no permission named `{$permissionName}` for guard `{$guardName}`.";

if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
return new static(Helpers::logAlertMessage($message));
}
}
10 changes: 2 additions & 8 deletions src/Exceptions/RoleAlreadyExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
namespace Maklad\Permission\Exceptions;

use InvalidArgumentException;
use Maklad\Permission\Helpers;

class RoleAlreadyExists extends InvalidArgumentException
{
public static function create(string $roleName, string $guardName)
{
$message = new static("A role `{$roleName}` already exists for guard `{$guardName}`.");

if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
return new static(Helpers::logAlertMessage("A role `{$roleName}` already exists for guard `{$guardName}`."));
}
}
10 changes: 2 additions & 8 deletions src/Exceptions/RoleDoesNotExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
namespace Maklad\Permission\Exceptions;

use InvalidArgumentException;
use Maklad\Permission\Helpers;

class RoleDoesNotExist extends InvalidArgumentException
{
public static function create(string $roleName)
{
$message = new static("There is no role named `{$roleName}`.");

if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
return new static(Helpers::logAlertMessage("There is no role named `{$roleName}`."));
}
}
16 changes: 16 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@ public static function getModelForGuard(string $guard)
return config("auth.providers.{$guard['provider']}.model");
})->get($guard);
}

/**
* Log Alert Message
* @param string $message
*
* @return string
*/
public static function logAlertMessage(string $message):string
{
if (config('permission.log_registration_exception')) {
$logger = app('log');
$logger->alert($message);
}

return $message;
}
}
6 changes: 4 additions & 2 deletions src/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public static function create(array $attributes = [])
{
$attributes['guard_name'] = $attributes['guard_name'] ?? config('auth.defaults.guard');

if (static::getPermissions()->where('name', $attributes['name'])->where('guard_name',
$attributes['guard_name'])->first()) {
if (static::getPermissions()->where('name', $attributes['name'])->where(
'guard_name',
$attributes['guard_name']
)->first()) {
throw PermissionAlreadyExists::create($attributes['name'], $attributes['guard_name']);
}

Expand Down

0 comments on commit fd889db

Please sign in to comment.