Skip to content

Commit

Permalink
Merge pull request romanbican#67 from lucasmichot/feature/code-style
Browse files Browse the repository at this point in the history
Enforce PSR2
  • Loading branch information
romanbican committed Jun 22, 2015
2 parents 93242f5 + 7b7ef21 commit 240bd70
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 15 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
composer.phar
composer.lock
.DS_Store
.php_cs.cache
.idea
14 changes: 14 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__);

$fixers = [
'short_array_syntax',
];

return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers($fixers)
->finder($finder);
4 changes: 4 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
preset: psr2

enabled:
- short_array_syntax
4 changes: 3 additions & 1 deletion src/Bican/Roles/Middleware/VerifyPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function __construct(Guard $auth)
*/
public function handle($request, Closure $next, $permission)
{
if ($this->auth->check() && $this->auth->user()->can($permission)) { return $next($request); }
if ($this->auth->check() && $this->auth->user()->can($permission)) {
return $next($request);
}

throw new PermissionDeniedException($permission);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Bican/Roles/Middleware/VerifyRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function __construct(Guard $auth)
*/
public function handle($request, Closure $next, $role)
{
if ($this->auth->check() && $this->auth->user()->is($role)) { return $next($request); }
if ($this->auth->check() && $this->auth->user()->is($role)) {
return $next($request);
}

throw new RoleDeniedException($role);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Bican/Roles/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function __construct(array $attributes = [])
{
parent::__construct($attributes);

if ($connection = config('roles.connection')) { $this->connection = $connection; }
if ($connection = config('roles.connection')) {
$this->connection = $connection;
}
}
}
4 changes: 3 additions & 1 deletion src/Bican/Roles/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function __construct(array $attributes = [])
{
parent::__construct($attributes);

if ($connection = config('roles.connection')) { $this->connection = $connection; }
if ($connection = config('roles.connection')) {
$this->connection = $connection;
}
}
}
40 changes: 30 additions & 10 deletions src/Bican/Roles/Traits/HasRoleAndPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function getRoles()
*/
public function is($role, $all = false)
{
if ($this->isPretendEnabled()) { return $this->pretend('is'); }
if ($this->isPretendEnabled()) {
return $this->pretend('is');
}

return $this->{$this->getMethodName('is', $all)}($this->getArrayFrom($role));
}
Expand All @@ -64,7 +66,9 @@ public function is($role, $all = false)
protected function isOne(array $roles)
{
foreach ($roles as $role) {
if ($this->hasRole($role)) { return true; }
if ($this->hasRole($role)) {
return true;
}
}

return false;
Expand All @@ -79,7 +83,9 @@ protected function isOne(array $roles)
protected function isAll(array $roles)
{
foreach ($roles as $role) {
if (!$this->hasRole($role)) { return false; }
if (!$this->hasRole($role)) {
return false;
}
}

return true;
Expand Down Expand Up @@ -147,7 +153,9 @@ public function level()
*/
public function rolePermissions()
{
if (!$roles = $this->getRoles()->lists('id')->toArray()) { $roles = []; }
if (!$roles = $this->getRoles()->lists('id')->toArray()) {
$roles = [];
}

$prefix = config('database.connections.' . config('database.default') . '.prefix');

Expand Down Expand Up @@ -186,7 +194,9 @@ public function getPermissions()
*/
public function can($permission, $all = false)
{
if ($this->isPretendEnabled()) { return $this->pretend('can'); }
if ($this->isPretendEnabled()) {
return $this->pretend('can');
}

return $this->{$this->getMethodName('can', $all)}($this->getArrayFrom($permission));
}
Expand All @@ -200,7 +210,9 @@ public function can($permission, $all = false)
protected function canOne(array $permissions)
{
foreach ($permissions as $permission) {
if ($this->hasPermission($permission)) { return true; }
if ($this->hasPermission($permission)) {
return true;
}
}

return false;
Expand All @@ -215,7 +227,9 @@ protected function canOne(array $permissions)
protected function canAll(array $permissions)
{
foreach ($permissions as $permission) {
if (!$this->hasPermission($permission)) { return false; }
if (!$this->hasPermission($permission)) {
return false;
}
}

return true;
Expand Down Expand Up @@ -245,9 +259,13 @@ protected function hasPermission($permission)
*/
public function allowed($providedPermission, Model $entity, $owner = true, $ownerColumn = 'user_id')
{
if ($this->isPretendEnabled()) { return $this->pretend('allowed'); }
if ($this->isPretendEnabled()) {
return $this->pretend('allowed');
}

if ($owner === true && $entity->{$ownerColumn} == $this->id) { return true; }
if ($owner === true && $entity->{$ownerColumn} == $this->id) {
return true;
}

return $this->isAllowed($providedPermission, $entity);
}
Expand All @@ -264,7 +282,9 @@ protected function isAllowed($providedPermission, Model $entity)
foreach ($this->getPermissions() as $permission) {
if ($permission->model != '' && get_class($entity) == $permission->model
&& ($permission->id == $providedPermission || $permission->slug === $providedPermission)
) { return true; }
) {
return true;
}
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/config/roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
|
| If you want, you can replace default models from this package by models
| you created. Have a look at `Bican\Roles\Models\Role` model and
| `Bican\Roles\Models\Permission` model.
| `Bican\Roles\Models\Permission` model.
|
*/

Expand Down

0 comments on commit 240bd70

Please sign in to comment.