Completed
Pull Request — master (#275)
by thomas
169:06 queued 99:08
created

ScriptInfoFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 92.31%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 6
dl 0
loc 23
ccs 12
cts 13
cp 0.9231
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 16 4
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Factory;
4
5
use BitWasp\Bitcoin\Script\ScriptFactory;
6
use BitWasp\Bitcoin\Script\ScriptInfo\ScriptHash;
7
use BitWasp\Bitcoin\Script\ScriptInfo\Multisig;
8
use BitWasp\Bitcoin\Script\ScriptInfo\PayToPubkey;
9
use BitWasp\Bitcoin\Script\ScriptInfo\PayToPubkeyHash;
10
use BitWasp\Bitcoin\Script\ScriptInterface;
11
12
class ScriptInfoFactory
13
{
14
    /**
15
     * @param ScriptInterface $script
16
     * @return \BitWasp\Bitcoin\Script\ScriptInfo\ScriptInfoInterface
17
     */
18
    public function load(ScriptInterface $script)
19 135
    {
20
        $classifier = ScriptFactory::scriptPubKey()->classify($script);
21 135
22 135
        if ($classifier->isMultisig()) {
23 48
            $handler = new Multisig($script);
24 6
        } elseif ($classifier->isPayToPublicKey()) {
25
            $handler = new PayToPubkey($script);
26
        } elseif ($classifier->isPayToPublicKeyHash()) {
27 42
            $handler = new PayToPubkeyHash($script);
28 129
        } else {
29
            throw new \InvalidArgumentException('Unparsable script type');
30 87
        }
31 24
32 87
        return $handler;
33 57
    }
34
}
35