CallableQualifier::__construct()   A
last analyzed

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
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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\NodalFlowException;
14
15
/**
16
 * Class CallableQualifier
17
 */
18
class CallableQualifier extends QualifierAbstract
19
{
20
    /**
21
     * @var callable
22
     */
23
    protected $qualifier;
24
25
    /**
26
     * Instantiate a CallableQualifier Node
27
     *
28
     * @param callable $qualifier
29
     *
30
     * @throws NodalFlowException
31
     */
32
    public function __construct(callable $qualifier)
33
    {
34
        $this->qualifier = $qualifier;
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Qualifies a record to either keep it, skip it or break the flow at the execution point
40
     * or at any upstream Node
41
     *
42
     * @param mixed $param
43
     *
44
     * @return InterrupterInterface|bool|null `true` to accept the record, eg let the Flow proceed untouched
45
     *                                        `false|null|void` to deny the record, eg trigger a continue on the carrier Flow (not ancestors)
46
     *                                        `InterrupterInterface` to trigger an interrupt with a target (which may be one ancestor)
47
     */
48
    public function qualify($param)
49
    {
50
        return \call_user_func($this->qualifier, $param);
51
    }
52
}
53