Completed
Pull Request — master (#492)
by thomas
106:30 queued 33:27
created

ScriptBranch::__debugInfo()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 6
nop 0
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Path;
4
5
use BitWasp\Bitcoin\Script\ScriptFactory;
6
use BitWasp\Bitcoin\Script\ScriptInterface;
7
8
class ScriptBranch
9
{
10
    /**
11
     * @var ScriptInterface
12
     */
13
    private $fullScript;
14
15
    /**
16
     * @var array|\array[]
17
     */
18
    private $segments;
19
20
    /**
21
     * @var array|\bool[]
22
     */
23
    private $branch;
24
25
    /**
26
     * ScriptBranch constructor.
27
     * @param ScriptInterface $fullScript
28
     * @param array $branch
29
     * @param PathTrace $segments
30
     */
31
    public function __construct(ScriptInterface $fullScript, array $branch, PathTrace $segments)
32
    {
33
        $this->fullScript = $fullScript;
34
        $this->branch = $branch;
35
        $this->segments = $segments;
0 ignored issues
show
Documentation Bug introduced by
It seems like $segments of type object<BitWasp\Bitcoin\Script\Path\PathTrace> is incompatible with the declared type array of property $segments.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
    }
37
38
    /**
39
     * @return ScriptInterface
40
     */
41
    public function getFullScript()
42
    {
43
        return $this->fullScript;
44
    }
45
46
    /**
47
     * @return array|\bool[]
48
     */
49
    public function getBranchDescriptor()
50
    {
51
        return $this->branch;
52
    }
53
54
    /**
55
     * @return array|\array[]|PathTrace
56
     */
57
    public function getSegments()
58
    {
59
        return $this->segments;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function getOps()
66
    {
67
        $sequence = [];
68
        foreach ($this->segments as $segment) {
69
            $sequence = array_merge($sequence, $segment->all());
70
        }
71
        return $sequence;
72
    }
73
74
    /**
75
     * @return ScriptInterface
76
     */
77
    public function getNeuteredScript()
78
    {
79
        return ScriptFactory::fromOperations($this->getOps());
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function __debugInfo()
86
    {
87
        $m = [];
88
        foreach ($this->segments as $segment) {
89
            $m[] = ScriptFactory::fromOperations($segment->all());
90
        }
91
92
        $path = [];
93
        foreach ($this->branch as $flag) {
94
            $path[] = $flag ? 'true' : 'false';
95
        }
96
97
        return [
98
            'branch' => implode(", ", $path),
99
            'segments' => $m,
100
        ];
101
    }
102
103
    /**
104
     * @return OperationContainer[]
105
     */
106
    public function getSignSteps()
107
    {
108
        $steps = [];
109
        foreach ($this->segments as $segment) {
110
            if (!$segment->isLoneLogicalOp()) {
111
                $steps[] = $segment;
112
            }
113
        }
114
115
        return $steps;
116
    }
117
}
118