Completed
Push — master ( 1bcaea...79936a )
by Peter
02:56
created

SymfonySitemapBuilder::build()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.9379

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 9
cts 17
cp 0.5294
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 17
nc 3
nop 1
crap 3.9379
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\Builder\Sitemap;
11
12
use GpsLab\Component\Sitemap\Builder\Url\UrlBuilderCollection;
13
use GpsLab\Component\Sitemap\Stream\Stream;
14
use Symfony\Component\Console\Style\SymfonyStyle;
15
16
class SymfonySitemapBuilder
17
{
18
    /**
19
     * @var UrlBuilderCollection
20
     */
21
    private $builders;
22
23
    /**
24
     * @var Stream
25
     */
26
    private $stream;
27
28
    /**
29
     * @param UrlBuilderCollection $builders
30
     * @param Stream               $stream
31
     */
32 1
    public function __construct(UrlBuilderCollection $builders, Stream $stream)
33
    {
34 1
        $this->builders = $builders;
35 1
        $this->stream = $stream;
36 1
    }
37
38
    /**
39
     * @param SymfonyStyle $io
40
     *
41
     * @return int
42
     */
43 1
    public function build(SymfonyStyle $io)
44
    {
45 1
        $total_builders = count($this->builders);
46 1
        $this->stream->open();
47
48 1
        foreach ($this->builders as $i => $builder) {
49 1
            $io->section(sprintf(
50 1
                '[%d/%d] Build by <info>%s</info> builder',
51 1
                $i + 1,
52 1
                $total_builders,
53 1
                $builder->getName()
54
            ));
55
56
            $io->progressStart(count($builder));
57
            foreach ($builder as $url) {
58
                $this->stream->push($url);
59
                $io->progressAdvance();
60
            }
61
            $io->progressFinish();
62
        }
63
64
        $total_urls = count($this->stream);
65
        $this->stream->close();
66
67
        return $total_urls;
68
    }
69
}
70