Customer   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
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 57
ccs 21
cts 21
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 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