Customer::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Services\Registration;
6
7
use stdClass;
8
9
class Customer
10
{
11
    /** @var stdClass */
12
    private $data;
13
14
    /** @var CustomerStatus */
15
    private $status;
16
17
    /** @var CustomerType */
18
    private $type;
19
20 22
    public function __construct(stdClass $raw)
21
    {
22 22
        $this->data = $raw;
23 22
        $rawStatus = $this->get('status');
24 22
        if (in_array($rawStatus, CustomerStatus::toArray())) {
25 20
            $this->status = new CustomerStatus($rawStatus);
26
        } else {
27 2
            $this->status = CustomerStatus::suspended();
28
        }
29 22
        $this->type = (-1 === $this->credit()) ? CustomerType::ondemand() : CustomerType::prepaid();
30
    }
31
32 22
    private function get(string $keyword): string
33
    {
34 22
        return strval($this->data->{$keyword} ?? '');
35
    }
36
37 5
    public function status(): CustomerStatus
38
    {
39 5
        return $this->status;
40
    }
41
42 1
    public function counter(): int
43
    {
44 1
        return intval($this->get('counter'));
45
    }
46
47 15
    public function rfc(): string
48
    {
49 15
        return $this->get('taxpayer_id');
50
    }
51
52 22
    public function credit(): int
53
    {
54 22
        return intval($this->get('credit'));
55
    }
56
57 7
    public function customerType(): CustomerType
58
    {
59 7
        return $this->type;
60
    }
61
62
    /** @return array<mixed> */
63 2
    public function values(): array
64
    {
65 2
        return (array) $this->data;
66
    }
67
}
68