Completed
Pull Request — master (#526)
by thomas
71:08
created

ScriptBranch::getSignSteps()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 0
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 12
rs 9.4285
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 $scriptSections;
19
20
    /**
21
     * @var array|\bool[]
22
     */
23
    private $branch;
24
25
    /**
26
     * ScriptBranch constructor.
27
     * @param ScriptInterface $fullScript
28
     * @param array $logicalPath
29
     * @param array $scriptSections
30
     */
31
    public function __construct(ScriptInterface $fullScript, array $logicalPath, array $scriptSections)
32 154
    {
33
        $this->fullScript = $fullScript;
34 154
        $this->branch = $logicalPath;
35 154
        $this->scriptSections = $scriptSections;
36 154
    }
37 154
38
    /**
39
     * @return array|\bool[]
40
     */
41
    public function getPath()
42
    {
43
        return $this->branch;
44
    }
45
46
    /**
47
     * @return array|\array[]
48
     */
49
    public function getScriptSections()
50 154
    {
51
        return $this->scriptSections;
52 154
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getOps()
58 136
    {
59
        $sequence = [];
60 136
        foreach ($this->scriptSections as $segment) {
61
            $sequence = array_merge($sequence, $segment);
62
        }
63
        return $sequence;
64
    }
65
66 18
    /**
67
     * @return array
68 18
     */
69 18
    public function __debugInfo()
70 18
    {
71
        $m = [];
72 18
        foreach ($this->scriptSections as $segment) {
73
            $m[] = ScriptFactory::fromOperations($segment);
74
        }
75
76
        $path = [];
77
        foreach ($this->branch as $flag) {
78 18
            $path[] = $flag ? 'true' : 'false';
79
        }
80 18
81
        return [
82
            'branch' => implode(", ", $path),
83
            'segments' => $m,
84
        ];
85
    }
86
}
87