Completed
Pull Request — master (#13)
by Peter
06:35
created

MultiStream::push()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011-2019, 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
    public function __construct(Stream ...$streams)
27
    {
28
        $this->streams = $streams;
29
    }
30
31 8
    public function open(): void
32
    {
33 8
        foreach ($this->streams as $stream) {
34 8
            $stream->open();
35
        }
36 8
    }
37
38
    public function close(): void
39
    {
40
        foreach ($this->streams as $stream) {
41 8
            $stream->close();
42
        }
43 8
    }
44 8
45
    /**
46 2
     * @param Url $url
47
     */
48 2
    public function push(Url $url): void
49 2
    {
50
        foreach ($this->streams as $stream) {
51 2
            $stream->push($url);
52
        }
53 4
    }
54
}
55