Logic::fromConditionsArray()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of CaptainHook.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace CaptainHook\App\Hook\Condition;
15
16
use CaptainHook\App\Hook\Condition;
17
18
/**
19
 * Logical condition base class
20
 *
21
 * @package CaptainHook
22
 * @author  Sebastian Feldmann <[email protected]>
23
 * @author  Andreas Heigl <[email protected]>
24
 * @link    https://github.com/captainhook-git/captainhook
25
 * @since   Class available since Release 5.7.0
26
 */
27
abstract class Logic implements Condition
28
{
29
    /**
30
     * List of conditions to logically connect
31
     *
32
     * @var \CaptainHook\App\Hook\Condition[]
33
     */
34
    protected array $conditions = [];
35
36 2
    final private function __construct(Condition ...$conditions)
37
    {
38 2
        $this->conditions = $conditions;
39
    }
40
41
    /**
42
     * Create a logic condition
43
     *
44
     * @param  array<Condition> $conditions
45
     * @return \CaptainHook\App\Hook\Condition
46
     */
47 7
    public static function fromConditionsArray(array $conditions): Condition
48
    {
49 7
        $realConditions = [];
50 7
        foreach ($conditions as $condition) {
51 7
            if (! $condition instanceof Condition) {
52 1
                continue;
53
            }
54 7
            $realConditions[] = $condition;
55
        }
56
57 7
        return new static(...$realConditions);
58
    }
59
}
60