Completed
Pull Request — master (#162)
by
unknown
08:31
created

XmlResponseModel::__construct()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 10

Duplication

Lines 7
Ratio 41.18 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 10
c 1
b 0
f 1
nc 6
nop 1
dl 7
loc 17
rs 9.2
1
<?php
2
namespace Yandex\Common;
3
4
/**
5
 * XmlResponseModel for responses of Yandex API in XML Format.
6
 *
7
 * @package Yandex\Common
8
 */
9
abstract class XmlResponseModel extends Model
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14
    public function __construct(\SimpleXMLIterator $data)
15
    {
16
        $propertyName = $data->getName();
17
        $ourPropertyName = array_search($propertyName, $this->propNameMap, true);
18
19
        if (false !== $ourPropertyName) {
20
            $propertyName = $ourPropertyName;
21
        }
22
23 View Code Duplication
        if (property_exists($this, $propertyName)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
            if (array_key_exists($propertyName, $this->mappingClasses)) {
25
                $this->{$propertyName} = new $this->mappingClasses[$propertyName]($data);
26
            } else {
27
                $this->{$propertyName} = (string)$data;
28
            }
29
        }
30
    }
31
}
32