Completed
Pull Request — master (#348)
by thomas
72:50 queued 67:29
created

ScriptWitness::__clone()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 6
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Script;
4
5
use BitWasp\Bitcoin\Collection\StaticBufferCollection;
6
use BitWasp\Bitcoin\Serializer\Script\ScriptWitnessSerializer;
7
8
class ScriptWitness extends StaticBufferCollection implements ScriptWitnessInterface
9
{
10
    /**
11
     * @param ScriptWitnessInterface $witness
12
     * @return bool
13
     */
14
    public function equals(ScriptWitnessInterface $witness)
15
    {
16
        $nStack = count($this);
17
        if ($nStack !== count($witness)) {
18
            return false;
19
        }
20
21
        for ($i = 0; $i < $nStack; $i++) {
22
            if (false === $this->offsetGet($i)->equals($witness->offsetGet($i))) {
23
                return false;
24
            }
25
        }
26
27
        return true;
28
    }
29
30
    /**
31
     * @return \BitWasp\Buffertools\BufferInterface
32
     */
33 27
    public function getBuffer()
34
    {
35 27
        return (new ScriptWitnessSerializer())->serialize($this);
36
    }
37
}
38