Completed
Pull Request — master (#591)
by thomas
22:54 queued 09:12
created

TransactionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 4 1
A mutate() 0 4 1
A fromHex() 0 4 1
A fromBuffer() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Transaction;
6
7
use BitWasp\Bitcoin\Serializer\Transaction\TransactionSerializer;
8
use BitWasp\Bitcoin\Transaction\Factory\TxBuilder;
9
use BitWasp\Bitcoin\Transaction\Mutator\TxMutator;
10
use BitWasp\Buffertools\Buffer;
11
use BitWasp\Buffertools\BufferInterface;
12
13
class TransactionFactory
14
{
15
    /**
16
     * @return TxBuilder
17
     */
18 5
    public static function build(): TxBuilder
19
    {
20 5
        return new TxBuilder();
21
    }
22
23
    /**
24
     * @param TransactionInterface $transaction
25
     * @return TxMutator
26
     */
27 90
    public static function mutate(TransactionInterface $transaction): TxMutator
28
    {
29 90
        return new TxMutator($transaction);
30
    }
31
32
    /**
33
     * @param string $hex
34
     * @return TransactionInterface
35
     * @throws \Exception
36
     */
37 15
    public static function fromHex(string $hex): TransactionInterface
38
    {
39 15
        return self::fromBuffer(Buffer::hex($hex));
40
    }
41
42
    /**
43
     * @param BufferInterface $buffer
44
     * @return TransactionInterface
45
     */
46 22
    public static function fromBuffer(BufferInterface $buffer): TransactionInterface
47
    {
48 22
        return (new TransactionSerializer())->parse($buffer);
49
    }
50
}
51