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

KeeperResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 50
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addUri() 0 10 2
A save() 0 8 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
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