Passed
Push — master ( 71f366...5c9cf7 )
by Aleksandr
02:22
created

Price::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
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
 */
17
class Price extends Simple
18
{
19
    protected $type;
20
21
    public function __get($name)
22
    {
23
        if ($result = parent::__get($name)) {
24
            if ($this->type && ($value = $this->type->{$name})) {
25
                return $value;
26
            }
27
        }
28
        return $result;
29
    }
30
31
    public function __set($name, $value)
32
    {
33
    }
34
35
    public function __isset($name)
36
    {
37
    }
38
39
    public function defaultProperties()
40
    {
41
        return [
42
            'Представление' => 'performance',
43
            'ИдТипаЦены' => 'id',
44
            'ЦенаЗаЕдиницу' => 'cost',
45
            'Валюта' => 'currency',
46
            'Единица' => 'unit',
47
            'Коэффициент' => 'rate',
48
        ];
49
    }
50
51
    public function getType()
52
    {
53
        if (!$this->type && ($id = $this->id)) {
54
            if ($type = $this->owner->offerPackage->xpath("//c:ТипЦены[c:Ид = '{$id}']")) {
55
                $this->type = new Simple($this->owner, $type[0]);
56
            }
57
        }
58
        return $this->type;
59
    }
60
61
    public function init()
62
    {
63
        if ($this->xml && $this->xml->Цена) {
64
            foreach ($this->xml->Цена as $price) {
65
                $this->append(new self($this->owner, $price));
66
            }
67
            $this->getType();
68
        }
69
        parent::init();
70
    }
71
}