Completed
Push — 2.x-dev-kit ( 971030 )
by
unknown
07:52
created

SourceManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\SeoBundle\Sitemap;
13
14
use Exporter\Source\ChainSourceIterator;
15
use Exporter\Source\SourceIteratorInterface;
16
17
/**
18
 * SourceManager.
19
 *
20
 * Manager several chain source iterator grouped
21
 */
22
class SourceManager implements SourceIteratorInterface
23
{
24
    /**
25
     * @var \ArrayIterator
26
     */
27
    protected $sources;
28
29
    /**
30
     * Constructor.
31
     */
32
    public function __construct()
33
    {
34
        $this->sources = new \ArrayIterator();
35
    }
36
37
    /**
38
     * Adding source with his group.
39
     *
40
     * @param string                  $group
41
     * @param SourceIteratorInterface $source
42
     * @param array                   $types
43
     */
44
    public function addSource($group, SourceIteratorInterface $source, array $types = array())
45
    {
46
        if (!isset($this->sources[$group])) {
47
            $this->sources[$group] = new \stdClass();
48
49
            $this->sources[$group]->sources = new ChainSourceIterator();
50
            $this->sources[$group]->types = array();
51
        }
52
53
        $this->sources[$group]->sources->addSource($source);
54
55
        if ($types) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $types of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
56
            $this->sources[$group]->types += array_diff($types, $this->sources[$group]->types);
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function current()
64
    {
65
        return $this->sources->current();
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function next()
72
    {
73
        $this->sources->next();
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function key()
80
    {
81
        return $this->sources->key();
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function valid()
88
    {
89
        return $this->sources->valid();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function rewind()
96
    {
97
        $this->sources->rewind();
98
    }
99
}
100