NandOperator   A
last analyzed

Complexity

Total Complexity 3

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 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 10 3
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 NAND:
15
 * The output is "false" if both inputs are "true". Otherwise, the output is "true".
16
 */
17
final class NandOperator implements OperatorInterface
18
{
19
    public const CODE = 'nand';
20
21
    public function execute(...$expressions): bool
22
    {
23
        $count = count($expressions);
24
        $result = $expressions[0];
25
26
        for ($i = 1; $i < $count; $i++) {
27
            $result = !($result && $expressions[$i]);
28
        }
29
30
        return $result;
31
    }
32
}
33