for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Policies;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class UserPolicy
{
use HandlesAuthorization;
/**
* The before method will be executed before any other methods on the policy,
* giving you an opportunity to authorize the action before the intended
* policy method is actually called. This feature is most commonly used for
* authorizing application administrators to perform any action.
*/
public function before($user, $ability)
$user
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function before(/** @scrutinizer ignore-unused */ $user, $ability)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
$ability
public function before($user, /** @scrutinizer ignore-unused */ $ability)
// TODO: Admins...
// if ($user->isSuperAdmin()) {
// return true;
// }
return false;
}
* Determine whether the user can view the user.
*
* @param \App\User $user
* @return boolean
public function view(User $user, User $user2)
// TODO: Check if user role is > 0
return $user->role > 1 || $user->id === $user2->id;
* Determine whether the user can create users.
public function create(User $user)
public function create(/** @scrutinizer ignore-unused */ User $user)
// TODO: Check if user role > 1
return true;
* Determine whether the user can update the user2.
public function update(User $user, User $user2)
public function update(/** @scrutinizer ignore-unused */ User $user, User $user2)
$user2
public function update(User $user, /** @scrutinizer ignore-unused */ User $user2)
// Users can update themselves
//return $user->id === $user->id;
* Determine whether the user can delete the user.
public function delete(User $user, User $user2)
public function delete(/** @scrutinizer ignore-unused */ User $user, User $user2)
public function delete(User $user, /** @scrutinizer ignore-unused */ User $user2)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.