Passed
Pull Request — master (#1)
by Fabrice
03:00
created

QualifierAbstract   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
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
15
/**
16
 * Interface QualifierInterface
17
 */
18
abstract class QualifierAbstract extends NodeAbstract implements QualifierInterface
19
{
20
    /**
21
     * Indicate if this Node is traversable
22
     *
23
     * @var bool
24
     */
25
    protected $isATraversable = false;
26
27
    /**
28
     * Indicate if this Node is returning a value
29
     *
30
     * @var bool
31
     */
32
    protected $isAReturningVal = false;
33
34
    /**
35
     * Indicate if this Node is a Flow (Branch)
36
     *
37
     * @var bool
38
     */
39
    protected $isAFlow = false;
40
41
    /**
42
     * The CallableInterruptNode's payload interface is simple :
43
     *      - return false to break
44
     *      - return true to continue
45
     *      - return void|null (whatever) to proceed with the flow
46
     *
47
     * @param mixed $param
48
     *
49
     * @return mixed|void
50
     */
51
    public function exec($param)
52
    {
53
        $flowInterrupt = $this->qualify($param);
54
        if ($flowInterrupt === null) {
55
            // do nothing, let the flow proceed
56
            return;
57
        }
58
59
        if ($flowInterrupt instanceof  InterrupterInterface) {
60
            $flowInterruptType = $flowInterrupt->getType();
61
        } elseif ($flowInterrupt) {
62
            $flowInterruptType = InterrupterInterface::TYPE_CONTINUE;
63
            $flowInterrupt     = null;
64
        } else {
65
            $flowInterruptType = InterrupterInterface::TYPE_BREAK;
66
            $flowInterrupt     = null;
67
        }
68
69
        /* @var null|InterrupterInterface $flowInterrupt */
70
        $this->carrier->interruptFlow($flowInterruptType, $flowInterrupt);
71
    }
72
}
73