greaterThan example

$toCalculate->add($item);
        }
    }

    private function validate(CalculatedPrice $price, LineItemCollection $goods, Cart $cart): bool
    {
        if ($goods->count() <= 0) {
            return false;
        }

        if (FloatComparator::greaterThan($price->getTotalPrice(), 0)) {
            return true;
        }

        if (FloatComparator::equals($price->getTotalPrice(), 0)) {
            return false;
        }

        // should not be possible to get negative carts         $total = $price->getTotalPrice() + $cart->getLineItems()->getPrices()->sum()->getTotalPrice();

        return $total >= 0;
    }
if ($operator === Rule::OPERATOR_EMPTY) {
            return false;
        }

        if ($ruleValue === null) {
            return self::isNegativeOperator($operator);
        }

        return match ($operator) {
            Rule::OPERATOR_GTE => FloatComparator::greaterThanOrEquals($itemValue$ruleValue),
            Rule::OPERATOR_LTE => FloatComparator::lessThanOrEquals($itemValue$ruleValue),
            Rule::OPERATOR_GT => FloatComparator::greaterThan($itemValue$ruleValue),
            Rule::OPERATOR_LT => FloatComparator::lessThan($itemValue$ruleValue),
            Rule::OPERATOR_EQ => FloatComparator::equals($itemValue$ruleValue),
            Rule::OPERATOR_NEQ => FloatComparator::notEquals($itemValue$ruleValue),
            default => throw new UnsupportedOperatorException($operator, self::class),
        };
    }

    public static function string(?string $itemValue, string $ruleValue, string $operator): bool
    {
        if ($itemValue === null) {
            $itemValue = '';
        }
default => throw new UnsupportedOperatorException($operator, self::class),
        };
    }

    private function compareNumeric(string $operator, float $value, float $comparable): bool
    {
        return match ($operator) {
            Rule::OPERATOR_EQ => FloatComparator::equals($value$comparable),
            Rule::OPERATOR_NEQ => FloatComparator::notEquals($value$comparable),
            Rule::OPERATOR_GTE => FloatComparator::greaterThanOrEquals($value$comparable),
            Rule::OPERATOR_LTE => FloatComparator::lessThanOrEquals($value$comparable),
            Rule::OPERATOR_GT => FloatComparator::greaterThan($value$comparable),
            Rule::OPERATOR_LT => FloatComparator::lessThan($value$comparable),
            default => throw new UnsupportedOperatorException($operator, self::class),
        };
    }
}
0.3, 0.1 + 0.2, false],
            [0.4 - 0.1, 0.1 + 0.2, false],
            [0.1 + 0.1 + 0.1, 0.1 + 0.2, false],
        ];
    }

    /** * @dataProvider greaterThanDataProvider */
    public function testGreaterThan(float $a, float $b, bool $expected): void
    {
        static::assertSame($expected, FloatComparator::greaterThan($a$b));
    }

    /** * @return array{0: float, 1: float, 2: bool}[] */
    public static function greaterThanDataProvider(): array
    {
        return [
            [2, 1, true],
            [1.00001, 1, true],
            [0.00001, 0, true],
            [
default => throw new UnsupportedOperatorException($operator, self::class),
        };
    }

    private static function floatMatch(string $operator, float $actual, float $expected): bool
    {
        return match ($operator) {
            Rule::OPERATOR_NEQ => FloatComparator::notEquals($actual$expected),
            Rule::OPERATOR_GTE => FloatComparator::greaterThanOrEquals($actual$expected),
            Rule::OPERATOR_LTE => FloatComparator::lessThanOrEquals($actual$expected),
            Rule::OPERATOR_EQ => FloatComparator::equals($actual$expected),
            Rule::OPERATOR_GT => FloatComparator::greaterThan($actual$expected),
            Rule::OPERATOR_LT => FloatComparator::lessThan($actual$expected),
            default => throw new UnsupportedOperatorException($operator, self::class),
        };
    }

    /** * @param array<string, string> $renderedField * * @return Constraint[] */
    private static function getRenderedFieldValueConstraints(array $renderedField): array
    {
if ($this->zipCodes === null && $this->operator !== self::OPERATOR_EMPTY) {
            throw new UnsupportedValueException(\gettype($this->zipCodes), self::class);
        }

        $compareZipCode = \is_array($this->zipCodes) ? $this->zipCodes[0] : null;

        return match ($this->operator) {
            Rule::OPERATOR_EQ => !empty($this->getMatches($zipCode)),
            Rule::OPERATOR_NEQ => empty($this->getMatches($zipCode)),
            self::OPERATOR_GTE => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::greaterThanOrEquals((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_LTE => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::lessThanOrEquals((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_GT => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::greaterThan((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_LT => is_numeric($zipCode) && is_numeric($compareZipCode) && FloatComparator::lessThan((float) $zipCode(float) $compareZipCode),
            self::OPERATOR_EMPTY => empty($zipCode),
            default => throw new UnsupportedOperatorException($this->operator, self::class),
        };
    }

    /** * @return array<string> */
    private function getMatches(string $zipCode): array
    {
        
Home | Imprint | This part of the site doesn't use cookies.