Completed
Push — master ( 9c30d6...210d9b )
by Laurens
01:56
created

PayoutInfoBuilder::buildFromJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client\Finance;
6
7
use LauLamanApps\IzettleApi\API\Finance\Enum\Periodicity;
8
use LauLamanApps\IzettleApi\API\Finance\PayoutInfo;
9
use Money\Currency;
10
use Money\Money;
11
use Psr\Http\Message\ResponseInterface;
12
13
final class PayoutInfoBuilder implements PayoutInfoBuilderInterface
14
{
15 2
    public function buildFromJson(string $json): PayoutInfo
16
    {
17 2
        $data = json_decode($json, true)['data'];
18
19 2
        $currency = new Currency($data['currencyId']);
20
21 2
        return new PayoutInfo(
22 2
            new Money($data['totalBalance'], $currency),
23 2
            new Money($data['nextPayoutAmount'], $currency),
24 2
            new Money($data['discountRemaining'], $currency),
25 2
            Periodicity::get($data['periodicity'])
26
        );
27
    }
28
}
29