Passed
Push — master ( 1cde7b...7c9c8d )
by Aleksandr
08:27
created

Price::init()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 2
nop 0
crap 4
1
<?php
2
3
4
namespace Zenwalker\CommerceML\Model;
5
6
7
/**
8
 * Class Price
9
 *
10
 * @package Zenwalker\CommerceML\Model
11
 * @property string performance
12
 * @property string cost
13
 * @property string currency
14
 * @property string unit
15
 * @property string rate
16
 * @property Simple type
17
 */
18
class Price extends Simple
19
{
20
    protected $type;
21
22 1
    public function __get($name)
23
    {
24 1
        if ($result = parent::__get($name)) {
25 1
            if ($this->type && ($value = $this->type->{$name})) {
26
                return $value;
27
            }
28
        }
29 1
        return $result;
30
    }
31
32 1
    public function propertyAliases()
33
    {
34
        return [
35 1
            'Представление' => 'performance',
36
            'ИдТипаЦены' => 'id',
37
            'ЦенаЗаЕдиницу' => 'cost',
38
            'Валюта' => 'currency',
39
            'Единица' => 'unit',
40
            'Коэффициент' => 'rate',
41
        ];
42
    }
43
44 1
    public function getType()
45
    {
46 1
        if (!$this->type && ($id = $this->id)) {
47 1
            if ($type = $this->owner->offerPackage->xpath('//c:ТипЦены[c:Ид = :id]', ['id' => $id])) {
48 1
                $this->type = new Simple($this->owner, $type[0]);
49
            }
50
        }
51 1
        return $this->type;
52
    }
53
54 1
    public function init()
55
    {
56 1
        if ($this->xml && $this->xml->Цена) {
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' on line 56 at column 38
Loading history...
57 1
            foreach ($this->xml->Цена as $price) {
58 1
                $this->append(new self($this->owner, $price));
59
            }
60 1
            $this->getType();
61
        }
62 1
        parent::init();
63
    }
64
}