MultiStream::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Component\Sitemap\Stream;
11
12
use GpsLab\Component\Sitemap\Url\Url;
13
14
class MultiStream implements Stream
15
{
16
    /**
17
     * @var Stream[]
18
     */
19
    private $streams = [];
20
21
    /**
22
     * @var int
23
     */
24
    private $counter = 0;
25
26
    /**
27
     * @param Stream $stream1
28
     * @param Stream $stream2
29
     * @param Stream ...
30
     */
31 8
    public function __construct(Stream $stream1, Stream $stream2)
32
    {
33 8
        if (func_num_args() === 2) {
34 4
            $this->addStream($stream1);
35 4
            $this->addStream($stream2);
36
        } else {
37 4
            foreach (func_get_args() as $stream) {
38 4
                $this->addStream($stream);
39
            }
40
        }
41 8
    }
42
43
    /**
44
     * @param Stream $stream
45
     */
46 8
    private function addStream(Stream $stream)
47
    {
48 8
        $this->streams[] = $stream;
49 8
    }
50
51 2
    public function open()
52
    {
53 2
        foreach ($this->streams as $stream) {
54 2
            $stream->open();
55
        }
56 2
    }
57
58 4
    public function close()
59
    {
60 4
        foreach ($this->streams as $stream) {
61 4
            $stream->close();
62
        }
63 4
        $this->counter = 0;
64 4
    }
65
66
    /**
67
     * @param Url $url
68
     */
69 4
    public function push(Url $url)
70
    {
71 4
        foreach ($this->streams as $stream) {
72 4
            $stream->push($url);
73
        }
74 4
        ++$this->counter;
75 4
    }
76
77
    /**
78
     * @return int
79
     */
80 4
    public function count()
81
    {
82 4
        return $this->counter;
83
    }
84
}
85