Hackzilla\PasswordGenerator\Generator\RequirementPasswordGenerator::validLimits PHP Method

validLimits() public method

public validLimits ( )
    public function validLimits()
    {
        $elements = 0;
        if ($this->getOptionValue(self::OPTION_UPPER_CASE)) {
            $elements++;
        }
        if ($this->getOptionValue(self::OPTION_LOWER_CASE)) {
            $elements++;
        }
        if ($this->getOptionValue(self::OPTION_NUMBERS)) {
            $elements++;
        }
        if ($this->getOptionValue(self::OPTION_SYMBOLS)) {
            $elements++;
        }
        // check if there is wiggle room in minimums
        $total = 0;
        foreach ($this->minimumCounts as $minOption => $minCount) {
            $total += $minCount;
        }
        if ($total > $this->getLength()) {
            return false;
        }
        // check if there is wiggle room in maximums
        if ($elements <= count($this->maximumCounts)) {
            $total = 0;
            foreach ($this->maximumCounts as $maxOption => $maxCount) {
                $total += $maxCount;
            }
            if ($total < $this->getLength()) {
                return false;
            }
        }
        return true;
    }