Passed
Push — master ( 61b2f8...584670 )
by Chubarov
05:03
created

Receipt   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 50
rs 10
c 2
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getShopInn() 0 3 1
A getAddress() 0 3 1
A getDataTimeString() 0 4 1
A getTotalSum() 0 3 1
A __construct() 0 4 1
A getKktRegId() 0 3 1
A getProducts() 0 3 1
A getShopName() 0 3 1
A getCashierName() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Fns;
5
6
use Carbon\Carbon;
7
8
class Receipt
9
{
10
    private $data;
11
    private $products;
12
13
    public function __construct(string $json)
14
    {
15
        $this->data = json_decode($json);
16
        $this->products = new ProductCollection($this->data->content->items);
17
    }
18
19
    public function getProducts():ProductCollection
20
    {
21
        return $this->products;
22
    }
23
24
    public function getAddress():?string
25
    {
26
        return $this->data->content->retailPlaceAddress ?? $this->data->address ?? null;
27
    }
28
29
    public function getShopName():?string
30
    {
31
        return $this->data->content->user ?? null;
32
    }
33
34
    public function getShopInn() :int
35
    {
36
        return (int)$this->data->content->userInn;
37
    }
38
39
    public function getCashierName() :?string
40
    {
41
        return $this->data->content->operator ?? null;
42
    }
43
44
    public function getTotalSum():int
45
    {
46
        return $this->data->content->totalSum;
47
    }
48
49
    public function getKktRegId() :string
50
    {
51
        return $this->data->content->kktRegId;
52
    }
53
54
    public function getDataTimeString(): string
55
    {
56
        return Carbon::createFromTimestamp($this->data->content->dateTime, 'UTC')
57
                ->toDateTimeString();
58
    }
59
}
60