public static function checkPermission($userId = false)
    {
        $user = \Phramework\Phramework::getUser();

        //If user is not authenticated throw an \Exception
        if (!$user) {
            throw new \Phramework\Exceptions\UnauthorizedException();
        }

        //Check if speficied user is same as current user
        if ($userId !== false && $user->id != $userId) {
            throw new PermissionException(
                'Insufficient permissions'
            );
        }

        return $user;
    }