XnorOperator::execute()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 3
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
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 XnorOperator
14
 *
15
 * The XNOR (exclusive-NOR):
16
 * The output is "true" if the inputs are the same, and "false" if the inputs are different.
17
 */
18
final class XnorOperator implements OperatorInterface
19
{
20
    public const CODE = 'xnor';
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; $i < $count; $i++) {
31
            $result = !($result xor $expressions[$i]);
32
        }
33
34
        return $result;
35
    }
36
}
37