AndOperator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 14
rs 10
c 1
b 0
f 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 10 4
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\Logical;
9
10
use LogicTree\Operator\OperatorInterface;
11
use function count;
12
13
/**
14
 * The AND:
15
 * The output is "true" when both inputs are "true.". Otherwise, the output is "false".
16
 */
17
final class AndOperator implements OperatorInterface
18
{
19
    public const CODE = 'and';
20
21
    public function execute(...$expressions): bool
22
    {
23
        $count = count($expressions);
24
        $result = $expressions[0];
25
26
        for ($i = 1; $result && $i < $count; $i++) {
27
            $result = $result && $expressions[$i];
28
        }
29
30
        return $result;
31
    }
32
}
33