Passed
Branch master (f21f03)
by Roman
02:50 queued 22s
created

HistoryItemFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 31
c 1
b 0
f 0
dl 0
loc 45
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createFromRow() 0 37 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Skrill\Factory;
6
7
use DateTimeImmutable;
8
use Skrill\Response\HistoryItem;
9
use Skrill\Exception\SkrillResponseException;
10
11
/**
12
 * Class HistoryItemFactory
13
 */
14
class HistoryItemFactory
15
{
16
    /**
17
     * @param array $row
18
     *
19
     * @return HistoryItem
20
     * @throws SkrillResponseException
21
     */
22
    public static function createFromRow(array $row): HistoryItem
23
    {
24
        [
25
            ,
26
            $time,
27
            $type,
28
            $details,
29
            $lesion,
30
            $profit,
31
            $status,
32
            $balance,
33
            $reference,
34
            $amount,
35
            $currency,
36
            $info,
37
            $skrillId,
38
            $paymentType,
39
        ] = $row;
40
41
        if (!$datetime = DateTimeImmutable::createFromFormat('d M y H:i', $time)) {
42
            throw SkrillResponseException::fromSkillError(sprintf('Invalid time "%s".', $time));
43
        }
44
45
        return new HistoryItem(
46
            $reference,
47
            $skrillId,
48
            $datetime,
49
            $type,
50
            $details,
51
            $lesion,
52
            $profit,
53
            $status,
54
            $balance,
55
            $amount,
56
            $currency,
57
            $info,
58
            $paymentType
59
        );
60
    }
61
}
62