LogicTreeFacade   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 4
eloc 9
c 4
b 2
f 1
dl 0
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createDataSource() 0 3 1
A addOperator() 0 4 1
A executeCombineConditions() 0 3 1
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;
9
10
use LogicTree\Node\NodeInterface;
11
use LogicTree\Operator\OperatorInterface;
12
use LogicTree\Operator\OperatorPool;
13
use LogicTree\Service\ConditionManager;
14
15
class LogicTreeFacade
16
{
17
    /**
18
     * @var ConditionManager
19
     */
20
    private $conditionManager;
21
22
    /**
23
     * @var OperatorPool
24
     */
25
    private $operatorPool;
26
27
    public function __construct(?ConditionManager $conditionManager = null)
28
    {
29
        $this->operatorPool = new OperatorPool();
30
        $this->conditionManager = $conditionManager ?? new ConditionManager($this->operatorPool);
31
    }
32
33
    public function addOperator(string $type, string $operatorCode, OperatorInterface $operator): LogicTreeFacade
34
    {
35
        $this->operatorPool->addOperator($type, $operatorCode, $operator);
36
        return $this;
37
    }
38
39
    public function createDataSource(iterable $data): DataSource
40
    {
41
        return new DataSource($data);
42
    }
43
44
    public function executeCombineConditions(NodeInterface $node, DataSource $dataSource): bool
45
    {
46
        return $this->conditionManager->execute($node, $dataSource);
47
    }
48
}
49