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

Customer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 56
ccs 22
cts 22
cp 1
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A rfc() 0 3 1
A get() 0 3 1
A customerType() 0 3 1
A status() 0 3 1
A counter() 0 3 1
A credit() 0 3 1
A values() 0 3 1
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