Completed
Push — master ( 68be21...073c54 )
by Kévin
02:41
created

Native::getOperators()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace RulerZ\Target\Native;
4
5
use RulerZ\Compiler\Context;
6
use RulerZ\Target\AbstractCompilationTarget;
7
8
class Native extends AbstractCompilationTarget
9
{
10
    /**
11
     * @inheritDoc
12
     */
13
    public function supports($target, $mode)
14
    {
15
        if ($mode === self::MODE_APPLY_FILTER) {
16
            return false;
17
        }
18
19
        // we can filter a collection
20
        if ($mode === self::MODE_FILTER) {
21
            return is_array($target) || $target instanceof \Traversable;
22
        }
23
24
        // and we know how to handle arrays and objects
25
        return is_array($target) || is_object($target);
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    protected function createVisitor(Context $context)
32
    {
33
        return new NativeVisitor($this->getOperators());
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    protected function getExecutorTraits()
40
    {
41
        return [
42
            '\RulerZ\Executor\ArrayTarget\FilterTrait',
43
            '\RulerZ\Executor\ArrayTarget\SatisfiesTrait',
44
        ];
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function getOperators()
51
    {
52
        return NativeOperators::create(parent::getOperators());
53
    }
54
}
55