Completed
Pull Request — master (#2)
by Jan-Petter
02:43
created

SitemapParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 15 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 1
cbo 2
dl 9
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A client() 0 4 1
A add() 0 11 3
A render() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace vipnytt\RobotsTxtParser\Parser\Directives;
3
4
use vipnytt\RobotsTxtParser\Client\Directives\SitemapClient;
5
use vipnytt\RobotsTxtParser\Parser\UrlParser;
6
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
7
8
/**
9
 * Class SitemapParser
10
 *
11
 * @package vipnytt\RobotsTxtParser\Parser\Directives
12
 */
13
class SitemapParser implements ParserInterface, RobotsTxtInterface
14
{
15
    use UrlParser;
16
17
    /**
18
     * Sitemap array
19
     * @var string[]
20
     */
21
    private $sitemaps = [];
22
23
    /**
24
     * Sitemap constructor.
25
     */
26
    public function __construct()
27
    {
28
    }
29
30
    /**
31
     * Add
32
     *
33
     * @param string $line
34
     * @return bool
35
     */
36
    public function add($line)
37
    {
38
        if (
39
            !$this->urlValidate(($url = $this->urlEncode($line))) ||
40
            in_array($url, $this->sitemaps)
41
        ) {
42
            return false;
43
        }
44
        $this->sitemaps[] = $url;
45
        return true;
46
    }
47
48
    /**
49
     * Client
50
     *
51
     * @return SitemapClient
52
     */
53
    public function client()
54
    {
55
        return new SitemapClient($this->sitemaps);
56
    }
57
58
    /**
59
     * Render
60
     *
61
     * @return string[]
62
     */
63 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $result = [];
66
        foreach ($this->sitemaps as $url) {
67
            $result[] = self::DIRECTIVE_SITEMAP . ':' . $url;
68
        }
69
        sort($result);
70
        return $result;
71
    }
72
}
73