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

ScriptBranch::__debugInfo()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 6
nop 0
dl 0
loc 17
ccs 5
cts 5
cp 1
crap 4
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 $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