Completed
Pull Request — master (#162)
by
unknown
06:39
created

Hosts   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 61
ccs 0
cts 20
cp 0
rs 10
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A add() 0 13 1
A getAll() 0 4 1
1
<?php
2
namespace Yandex\Webmaster\Models;
3
4
use Yandex\Common\ObjectModel;
5
6
/**
7
 * Class Hosts
8
 *
9
 * @package Yandex\Webmaster\Models
10
 */
11
class Hosts extends ObjectModel
12
{
13
    /**
14
     * @var array $collection a collection of Host objects
15
     */
16
    protected $collection = [];
17
18
    /**
19
     * @var array $mappingClasses
20
     */
21
    protected $mappingClasses = [];
22
23
    /**
24
     * @var array $propNameMap
25
     */
26
    protected $propNameMap = [];
27
28
    /**
29
     * Hosts constructor.
30
     *
31
     * @param \SimpleXMLIterator $data
32
     */
33
    public function __construct(\SimpleXMLIterator $data)
34
    {
35
        for ($data->rewind(); $data->valid(); $data->next()) {
36
            $this->add($data->current());
37
        }
38
39
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
40
    }
41
42
    /**
43
     * Add item
44
     *
45
     * @param \SimpleXMLIterator $hostXmlNode
46
     * @return $this
47
     */
48
    public function add(\SimpleXMLIterator $hostXmlNode)
49
    {
50
        $host = new Host($hostXmlNode);
51
52
        $hostPathArray = explode('/', parse_url($host->getHref(), PHP_URL_PATH));
53
        $hostId = array_pop($hostPathArray);
54
55
        $host->setId($hostId);
56
57
        $this->collection[] = $host;
58
59
        return $this;
60
    }
61
62
    /**
63
     * Get items
64
     *
65
     * @return array
66
     */
67
    public function getAll()
68
    {
69
        return $this->collection;
70
    }
71
}
72