AbstractCompareTwo::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 1
b 0
f 1
1
<?php
2
/**
3
 * Copyright © Thomas Klein, All rights reserved.
4
 * See LICENSE bundled with this library for license details.
5
 */
6
declare(strict_types=1);
7
8
namespace LogicTree\Operator\Comparator;
9
10
use InvalidArgumentException;
11
use LogicTree\Operator\OperatorInterface;
12
use function count;
13
14
abstract class AbstractCompareTwo implements OperatorInterface
15
{
16
    public function execute(...$expressions): bool
17
    {
18
        $count = count($expressions);
19
20
        if ($count !== 2) {
21
            throw new InvalidArgumentException('2 expressions expected, ' . $count . ' given.');
22
        }
23
24
        return $this->executeComparison($expressions[0], $expressions[1]);
25
    }
26
27
    /**
28
     * Execute the comparison for expressions
29
     *
30
     * @param mixed $expr1
31
     * @param mixed $expr2
32
     * @return bool
33
     */
34
    abstract public function executeComparison($expr1, $expr2): bool;
35
}
36