Completed
Push — master ( 0d3592...0bb29a )
by Peter
06:28
created

MultiStream   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 65
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A addStream() 0 4 1
A open() 0 6 2
A close() 0 6 2
A push() 0 7 2
A count() 0 4 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
    public function __construct(Stream $stream1, Stream $stream2)
2 ignored issues
show
Unused Code introduced by
The parameter $stream1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $stream2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        foreach (func_get_args() as $stream) {
34
            $this->addStream($stream);
35
        }
36
    }
37
38
    /**
39
     * @param Stream $stream
40
     */
41
    private function addStream(Stream $stream)
42
    {
43
        $this->streams[] = $stream;
44
    }
45
46
    public function open()
47
    {
48
        foreach ($this->streams as $stream) {
49
            $stream->open();
50
        }
51
    }
52
53
    public function close()
54
    {
55
        foreach ($this->streams as $stream) {
56
            $stream->close();
57
        }
58
    }
59
60
    /**
61
     * @param Url $url
62
     */
63
    public function push(Url $url)
64
    {
65
        foreach ($this->streams as $stream) {
66
            $stream->push($url);
67
        }
68
        ++$this->counter;
69
    }
70
71
    /**
72
     * @return int
73
     */
74
    public function count()
75
    {
76
        return $this->counter;
77
    }
78
}
79