public function areAllowed(array $testRoles, array $testActions)
    {
        //only check allow and deny if there is at least one matching role
        if (count($testRoles) == 0) {
            $testRoles = [''];
        }
        $roleMatch = false;
        foreach ($this->roles as $role) {
            if (count(
                array_filter(
                    $testRoles,
                    function ($testRole) use ($role) {
                    return preg_match($role, $testRole);
                    }
                )
            ) > 0
            ) {
                $roleMatch = true;
                break;
            }
        }

        if (!$roleMatch) {
            //Permission is neither explicitly allowed or denied.
            return new AllowedResult;
        }

        //check allow
        $allowMatches = 0;
        //check each testAction in turn
        foreach ($testActions as $testAction) {
            $allowMatch = count(
                array_filter(
                    $this->allow,
                    function ($action) use ($testAction) {
                        //first check that action matches at least one allow
                        return preg_match($action, $testAction);
                    }
                )
            ) > 0;

            $denyMatch = count(
                array_filter(
                    $this->deny,
                    function ($action) use ($testAction) {
                        //second check that action does not match any deny
                        return preg_match($action, $testAction);
                    }
                )
            ) > 0;

            if ($denyMatch) {
                //one or more actions are explicitly denied
                return new AllowedResult(false, [], [$this->stateField => $this->regex($this->states)]);
            }
            if ($allowMatch) {
                $allowMatches++;
            }
        }
        if ($allowMatches == count($testActions)) {
            //all actions are explicitly allowed
            return new AllowedResult(true, [], [$this->stateField => $this->regex($this->states)]);
        }

        //Permission is neither explicitly allowed or denied.
        return new AllowedResult;
    }