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

LoggerStream::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 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
use Psr\Log\LoggerInterface;
14
15
class LoggerStream implements Stream
16
{
17
    /**
18
     * @var LoggerInterface
19
     */
20
    private $logger;
21
22
    /**
23
     * @var int
24
     */
25
    private $counter = 0;
26
27
    /**
28
     * @param LoggerInterface $logger
29
     */
30
    public function __construct(LoggerInterface $logger)
31
    {
32
        $this->logger = $logger;
33
    }
34
35
    public function open()
36
    {
37
        // do nothing
38
    }
39
40
    public function close()
41
    {
42
        // do nothing
43
    }
44
45
    /**
46
     * @param Url $url
47
     */
48
    public function push(Url $url)
49
    {
50
        $this->logger->debug(sprintf('URL "%s" is added to sitemap', $url->getLoc()), [
51
            'changefreq' => $url->getChangeFreq(),
52
            'lastmod' => $url->getLastMod(),
53
            'priority' => $url->getPriority(),
54
        ]);
55
        ++$this->counter;
56
    }
57
58
    /**
59
     * @return int
60
     */
61
    public function count()
62
    {
63
        return $this->counter;
64
    }
65
}
66