PayloadNodeAbstract::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
rs 10
1
<?php
2
3
/*
4
 * This file is part of NodalFlow.
5
 *     (c) Fabrice de Stefanis / https://github.com/fab2s/NodalFlow
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\NodalFlow\Nodes;
11
12
use fab2s\NodalFlow\Flows\FlowInterface;
13
use fab2s\NodalFlow\NodalFlowException;
14
15
/**
16
 * abstract class PayloadNodeAbstract
17
 */
18
abstract class PayloadNodeAbstract extends NodeAbstract implements PayloadNodeInterface
19
{
20
    /**
21
     * The underlying executable or traversable Payload
22
     *
23
     * @var object|callable
24
     */
25
    protected $payload;
26
27
    /**
28
     * A Payload Node is supposed to be immutable, and thus
29
     * have no setters on $isAReturningVal and $isATraversable
30
     *
31
     * @param mixed $payload
32
     * @param bool  $isAReturningVal
33
     * @param bool  $isATraversable
34
     *
35
     * @throws NodalFlowException
36
     */
37
    public function __construct($payload, bool $isAReturningVal, bool $isATraversable = false)
38
    {
39
        $this->payload         = $payload;
40
        $this->isAFlow         = (bool) ($payload instanceof FlowInterface);
41
        $this->isAReturningVal = (bool) $isAReturningVal;
42
        // let wrong traversability be enforced by parent
43
        $this->isATraversable  = (bool) $isATraversable;
44
45
        parent::__construct();
46
    }
47
48
    /**
49
     * Get this Node's Payload
50
     *
51
     * @return object|callable
52
     */
53
    public function getPayload()
54
    {
55
        return $this->payload;
56
    }
57
}
58