Completed
Push — master ( ce7b38...6ec792 )
by Peter
04:34
created

KeeperResult::addUri()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
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
namespace GpsLab\Component\Sitemap\Result;
10
11
use GpsLab\Component\Sitemap\Uri\Keeper\KeeperInterface;
12
use GpsLab\Component\Sitemap\Uri\UriInterface;
13
14
class KeeperResult implements ResultInterface
15
{
16
    /**
17
     * @var KeeperInterface
18
     */
19
    protected $keeper;
20
21
    /**
22
     * @var integer
23
     */
24
    protected $total = 0;
25
26
    const LINKS_LIMIT = 50000;
27
28
    /**
29
     * @param KeeperInterface $keeper
30
     */
31
    public function __construct(KeeperInterface $keeper)
32
    {
33
        $this->keeper = $keeper;
34
    }
35
36
    /**
37
     * @param UriInterface $url
38
     *
39
     * @return self
40
     */
41
    public function addUri(UriInterface $url)
42
    {
43
        if ($this->total < self::LINKS_LIMIT) {
44
            $this->keeper->addUri($url);
45
            $this->total++;
46
47
        }
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return int
54
     */
55
    public function save()
56
    {
57
        $this->keeper->save();
58
        $total = $this->total;
59
        $this->total = 0;
60
61
        return $total;
62
    }
63
}
64