QualifierAbstract   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 62
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A exec() 0 20 4
1
<?php
2
3
/*
4
 * This file is part of YaEtl
5
 *     (c) Fabrice de Stefanis / https://github.com/fab2s/YaEtl
6
 * This source file is licensed under the MIT license which you will
7
 * find in the LICENSE file or at https://opensource.org/licenses/MIT
8
 */
9
10
namespace fab2s\YaEtl\Qualifiers;
11
12
use fab2s\NodalFlow\Flows\InterrupterInterface;
13
use fab2s\NodalFlow\Nodes\NodeAbstract;
14
use fab2s\YaEtl\YaEtlException;
15
16
/**
17
 * Abstract Class QualifierAbstract
18
 */
19
abstract class QualifierAbstract extends NodeAbstract implements QualifierInterface
20
{
21
    /**
22
     * Indicate if this Node is traversable
23
     *
24
     * @var bool
25
     */
26
    protected $isATraversable = false;
27
28
    /**
29
     * Indicate if this Node is returning a value
30
     *
31
     * @var bool
32
     */
33
    protected $isAReturningVal = false;
34
35
    /**
36
     * Indicate if this Node is a Flow (Branch)
37
     *
38
     * @var bool
39
     */
40
    protected $isAFlow = false;
41
42
    /**
43
     * @var array
44
     */
45
    protected $nodeIncrements = [
46
        'num_qualify' => 'num_exec',
47
    ];
48
49
    /**
50
     * The qualify's method interface is simple :
51
     *      - return true to qualify the record, that is to use it
52
     *      - return false|null|void to skip the record
53
     *      - return InterrupterInterface to leverage complete interruption features
54
     *
55
     * @param mixed $param
56
     *
57
     * @throws YaEtlException
58
     *
59
     * @return mixed|void
60
     */
61
    public function exec($param = null)
62
    {
63
        $qualifies = $this->qualify($param);
64
        if ($qualifies === true) {
65
            return;
66
        }
67
68
        if (empty($qualifies)) {
69
            $this->carrier->interruptFlow(InterrupterInterface::TYPE_CONTINUE);
70
71
            return;
72
        }
73
74
        if ($qualifies instanceof  InterrupterInterface) {
75
            $this->carrier->interruptFlow($qualifies->getType(), $qualifies);
76
77
            return;
78
        }
79
80
        throw new YaEtlException('Qualifier returned wrong type, only Boolean, nullish and InterrupterInterface are allowed');
81
    }
82
}
83