for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Containers\Authorization\Tasks;
use App\Containers\Authorization\Exceptions\UserNotAdminException;
use App\Containers\User\Models\User;
use App\Ship\Parents\Tasks\Task;
/**
* Class IsUserAdminTask.
*
* @author Mahmoud Zalt <[email protected]>
*/
class IsUserAdminTask extends Task
{
* @param \App\Containers\User\Models\User|null $user
* @return bool
public function run(User $user = null)
// check if is Admin
if (!$user->hasAdminRole()) {
$user
null
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:
function someFunction(A $objectMaybe = null) { if ($objectMaybe instanceof A) { $objectMaybe->doSomething(); } }
throw new UserNotAdminException();
}
return true;
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: