UniqueUrlPolicy::shouldVisit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * This file is part of sitemap-common.
4
 *
5
 * (c) 2016 Daniele Moraschi
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SiteMap\Policy;
12
13
14
use SiteMap\Http\Url;
15
16
class UniqueUrlPolicy implements Policy
17
{
18
    /**
19
     * @var array
20
     */
21
    private $cache = [];
22
23
    /**
24
     * @param Url $url
25
     * @return bool
26
     */
27
    public function shouldVisit(Url $url)
28
    {
29
        if (isset($this->cache[$url->getWebUrl()])) {
30
            return false;
31
        }
32
33
        return $this->cache[$url->getWebUrl()] = true;
34
    }
35
36
    /**
37
     * @return mixed
38
     */
39
    public function reset()
40
    {
41
        $this->cache = [];
42
        return $this;
43
    }
44
}