AbstractCompareOne::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 AbstractCompareOne implements OperatorInterface
15
{
16
    public function execute(...$expressions): bool
17
    {
18
        $count = count($expressions);
19
20
        if ($count !== 1) {
21
            throw new InvalidArgumentException('1 expression expected, ' . $count . ' given.');
22
        }
23
24
        return $this->executeComparison($expressions[0]);
25
    }
26
27
    /**
28
     * Execute the comparison for the expression
29
     *
30
     * @param mixed $expression
31
     * @return bool
32
     */
33
    abstract public function executeComparison($expression): bool;
34
}
35