Quotation   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 82
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fill() 0 10 3
A attributes() 0 4 1
A getCosts() 0 4 1
A getDeadline() 0 4 1
A __get() 0 4 1
1
<?php
2
namespace Axado;
3
4
class Quotation
5
{
6
    /**
7
     * Fields to be parsed after the response is returned.
8
     *
9
     * @var array
10
     */
11
    protected $possibleAttributes = [
12
        'transportadora_metaname' => 'name',
13
        'servico_metaname' => 'service_metaname',
14
        'servico_nome' => 'service_name',
15
        'cotacao_preco' => 'quotation_price',
16
        'cotacao_custo' => 'quotation_costs',
17
        'cotacao_prazo' => 'deadline',
18
        'cotacao_codigo' => 'quotation_id',
19
    ];
20
21
    /**
22
     * Parsed attributes.
23
     *
24
     * @var array
25
     */
26
    protected $attributes = [];
27
28
    /**
29
     * Fill this object with raw attributes given by Response.
30
     *
31
     * @param array $rawAttributes
32
     */
33
    public function fill(array $rawAttributes = [])
34
    {
35
        foreach ($rawAttributes as $key => $value) {
36
            if (array_key_exists($key, $this->possibleAttributes)) {
37
                $keyParsed = $this->possibleAttributes[$key];
38
39
                $this->attributes[$keyParsed] = $value;
40
            }
41
        }
42
    }
43
44
    /**
45
     * Return all attributes parsed.
46
     *
47
     * @return array
48
     */
49
    public function attributes(): array
50
    {
51
        return $this->attributes;
52
    }
53
54
    /**
55
     * Returns the cost.
56
     *
57
     * @return string|null
58
     */
59
    public function getCosts()
60
    {
61
        return $this->attributes['quotation_price'] ?? null;
62
    }
63
64
    /**
65
     * Returns the deadline in days.
66
     *
67
     * @return string|null
68
     */
69
    public function getDeadline()
70
    {
71
        return $this->attributes['deadline'] ?? null;
72
    }
73
74
    /**
75
     * Magic attribute getter.
76
     *
77
     * @param string $attributeName
78
     *
79
     * @return mixed
80
     */
81
    public function __get(string $attributeName)
82
    {
83
        return $this->attributes[$attributeName] ?? null;
84
    }
85
}
86