Passed
Push — master ( 191f59...1ee7f2 )
by Aleksandr
01:40
created

PropertyCollection::init()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 12
1
<?php
2
3
4
namespace Zenwalker\CommerceML\Collections;
5
6
7
use Zenwalker\CommerceML\Model\Property;
8
use Zenwalker\CommerceML\Model\Simple;
9
10
/**
11
 * Class ValueProperties
12
 *
13
 * @package Zenwalker\CommerceML\Model
14
 */
15
class PropertyCollection extends Simple
16
{
17
    /**
18
     * @param $id
19
     * @return Property|null
20
     */
21
    public function getById($id)
22
    {
23
        foreach ($this as $property) {
24
            if ($property->id == (string)$id) {
25
                return $property;
26
            }
27
        }
28
        return null;
29
    }
30
31
    protected function loadPropertiesValue()
32
    {
33
        foreach ($this->xml->ЗначенияСвойства as $property) {
34
            $properties = $this->owner->classifier->getProperties();
35
            $object = clone $properties->getById($property->Ид);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $properties->getById($property->Ид) targeting Zenwalker\CommerceML\Col...tyCollection::getById() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
36
            $object->productId = (string)$this->xpath('..')[0]->Ид;
37
            $object->init();
38
            $this->append($object);
39
        }
40
    }
41
42
    protected function loadProperties()
43
    {
44
        foreach ($this->xml->Свойство as $property) {
45
            $this->append(new Property($this->owner, $property));
46
        }
47
    }
48
49
    public function init()
50
    {
51
        if (isset($this->xml->ЗначенияСвойства)) {
52
            $this->loadPropertiesValue();
53
        }
54
        if (isset($this->xml->Свойство)) {
55
            $this->loadProperties();
56
        }
57
        parent::init();
58
    }
59
}