Native   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 14 5
A createVisitor() 0 4 1
A getExecutorTraits() 0 8 1
A getOperators() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RulerZ\Target\Native;
6
7
use RulerZ\Compiler\Context;
8
use RulerZ\Executor\ArrayTarget\ArgumentUnwrappingTrait;
9
use RulerZ\Executor\ArrayTarget\FilterTrait;
10
use RulerZ\Executor\ArrayTarget\SatisfiesTrait;
11
use RulerZ\Target\AbstractCompilationTarget;
12
use RulerZ\Target\Operators\Definitions;
13
14
class Native extends AbstractCompilationTarget
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function supports($target, string $mode): bool
20
    {
21
        if ($mode === self::MODE_APPLY_FILTER) {
22
            return false;
23
        }
24
25
        // we can filter a collection
26
        if ($mode === self::MODE_FILTER) {
27
            return is_array($target) || $target instanceof \Traversable;
28
        }
29
30
        // and we know how to handle arrays and objects
31
        return is_array($target) || is_object($target);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function createVisitor(Context $context)
38
    {
39
        return new NativeVisitor($this->getOperators());
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function getExecutorTraits()
46
    {
47
        return [
48
            FilterTrait::class,
49
            SatisfiesTrait::class,
50
            ArgumentUnwrappingTrait::class,
51
        ];
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getOperators(): Definitions
58
    {
59
        return NativeOperators::create(parent::getOperators());
60
    }
61
}
62