SourceManager::next()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\SeoBundle\Sitemap;
15
16
use ArrayIterator;
17
use Sonata\Exporter\Source\ChainSourceIterator;
18
use Sonata\Exporter\Source\SourceIteratorInterface;
19
use stdClass;
20
21
/**
22
 * Manager several chain source iterator grouped.
23
 */
24
final class SourceManager implements SourceIteratorInterface
25
{
26
    /**
27
     * @var \ArrayIterator
28
     */
29
    protected $sources;
30
31
    public function __construct()
32
    {
33
        $this->sources = new ArrayIterator();
34
    }
35
36
    /**
37
     * Adding source with his group.
38
     *
39
     * @param string $group
40
     */
41
    public function addSource($group, SourceIteratorInterface $source, array $types = []): void
42
    {
43
        if (!isset($this->sources[$group])) {
44
            $this->sources[$group] = new stdClass();
45
46
            $this->sources[$group]->sources = new ChainSourceIterator();
47
            $this->sources[$group]->types = [];
48
        }
49
50
        $this->sources[$group]->sources->addSource($source);
51
52
        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...
53
            $this->sources[$group]->types += array_diff($types, $this->sources[$group]->types);
54
        }
55
    }
56
57
    public function current()
58
    {
59
        return $this->sources->current();
60
    }
61
62
    public function next(): void
63
    {
64
        $this->sources->next();
65
    }
66
67
    public function key()
68
    {
69
        return $this->sources->key();
70
    }
71
72
    public function valid()
73
    {
74
        return $this->sources->valid();
75
    }
76
77
    public function rewind(): void
78
    {
79
        $this->sources->rewind();
80
    }
81
}
82