Completed
Pull Request — master (#11)
by Carlos C
03:41
created

Customer::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 9
    public function __construct(stdClass $raw)
21
    {
22 9
        $this->data = $raw;
23 9
        $rawStatus = strval($this->get('status'));
24 9
        if (in_array($rawStatus, CustomerStatus::toArray())) {
25 7
            $this->status = new CustomerStatus($rawStatus);
26
        } else {
27 2
            $this->status = CustomerStatus::suspended();
28
        }
29 9
        $this->type = (-1 === $this->credit()) ? CustomerType::ondemand() : CustomerType::prepaid();
30 9
    }
31
32 9
    private function get(string $keyword): string
33
    {
34 9
        return strval($this->data->{$keyword} ?? '');
35
    }
36
37 2
    public function status(): CustomerStatus
38
    {
39 2
        return $this->status;
40
    }
41
42 1
    public function counter(): int
43
    {
44 1
        return intval($this->get('counter'));
45
    }
46
47 4
    public function rfc(): string
48
    {
49 4
        return $this->get('taxpayer_id');
50
    }
51
52 9
    public function credit(): int
53
    {
54 9
        return intval($this->get('credit'));
55
    }
56
57 1
    public function customerType(): CustomerType
58
    {
59 1
        return $this->type;
60
    }
61
62 2
    public function values(): array
63
    {
64 2
        return (array) $this->data;
65
    }
66
}
67