Completed
Pull Request — master (#526)
by thomas
30:16
created

ScriptBranch::getScriptSections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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