AndOperator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 4

1 Method

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