Completed
Pull Request — master (#13)
by Peter
03:12
created

MultiStream::addStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011, Peter Gribanov
9
 * @license   http://opensource.org/licenses/MIT
10
 */
11
12
namespace GpsLab\Component\Sitemap\Stream;
13
14
use GpsLab\Component\Sitemap\Url\Url;
15
16
class MultiStream implements Stream
17
{
18
    /**
19
     * @var Stream[]
20
     */
21
    private $streams = [];
22
23
    /**
24
     * @param Stream ...$streams
25
     */
26 8
    public function __construct(Stream ...$streams)
27
    {
28 8
        $this->streams = $streams;
29 8
    }
30
31 2
    public function open(): void
32
    {
33 2
        foreach ($this->streams as $stream) {
34 2
            $stream->open();
35
        }
36 2
    }
37
38 4
    public function close(): void
39
    {
40 4
        foreach ($this->streams as $stream) {
41 4
            $stream->close();
42
        }
43 4
    }
44
45
    /**
46
     * @param Url $url
47
     */
48 4
    public function push(Url $url): void
49
    {
50 4
        foreach ($this->streams as $stream) {
51 4
            $stream->push($url);
52
        }
53 4
    }
54
}
55