Passed
Push — master ( b47dcf...3f2121 )
by Aleksandr
04:26 queued 49s
created

PropertyCollection::loadProperties()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
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 2
    public function getById($id)
22
    {
23 2
        foreach ($this as $property) {
24 2
            if ($property->id === (string)$id) {
25 2
                return $property;
26
            }
27
        }
28 1
        return null;
29
    }
30
31 2
    protected function loadPropertiesValue()
32
    {
33 2
        foreach ($this->xml->ЗначенияСвойства as $property) {
34 2
            $properties = $this->owner->classifier->getProperties();
35 2
            $object = clone $properties->getById((string)$property->Ид);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $properties->getById((string)$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 2
            $object->productId = (string)$this->xpath('..')[0]->Ид;
37 2
            $object->init();
38 2
            $this->append($object);
39
        }
40 2
    }
41
42 2
    protected function loadProperties()
43
    {
44 2
        foreach ($this->xml->Свойство as $property) {
45 2
            $this->append(new Property($this->owner, $property));
46
        }
47 2
    }
48
49 2
    public function init()
50
    {
51 2
        if (isset($this->xml->ЗначенияСвойства)) {
52 2
            $this->loadPropertiesValue();
53
        }
54 2
        if (isset($this->xml->Свойство)) {
55 2
            $this->loadProperties();
56
        }
57 2
        parent::init();
58
    }
59
}