Completed
Push — master ( dc3dad...b5f967 )
by Jan-Petter
01:56
created

Parser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 7

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 6
c 5
b 0
f 0
lcom 4
cbo 7
dl 0
loc 63
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSitemaps() 0 4 1
A getHost() 0 4 1
A getCleanParam() 0 4 1
A optimizeURL() 0 4 1
A userAgent() 0 9 1
1
<?php
2
namespace vipnytt\RobotsTxtParser;
3
4
use vipnytt\UserAgentParser;
5
6
class Parser extends Core
7
{
8
    /**
9
     * HTTP status code parser
10
     * @var StatusCodeParser
11
     */
12
    protected $statusCodeParser;
13
14
    protected $origin;
15
    protected $statusCode;
16
17
    public function __construct($RobotsTxtURL, $statusCode, $content, $encoding = self::ENCODING, $byteLimit = self::BYTE_LIMIT)
0 ignored issues
show
Unused Code introduced by
The parameter $encoding is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $byteLimit is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        parent::__construct($content, $encoding = self::ENCODING, $byteLimit = self::BYTE_LIMIT);
20
        $this->origin = $RobotsTxtURL;
21
        $this->statusCode = $statusCode;
22
    }
23
24
    /**
25
     * Get sitemaps
26
     *
27
     * @return array
28
     */
29
    public function getSitemaps()
30
    {
31
        return $this->sitemap->export();
32
    }
33
34
    /**
35
     * Get host
36
     *
37
     * @return string|null
38
     */
39
    public function getHost()
40
    {
41
        return $this->host->export();
42
    }
43
44
    /**
45
     * Get Clean-param
46
     *
47
     * @return array
48
     */
49
    public function getCleanParam()
50
    {
51
        return $this->cleanParam->export();
52
    }
53
54
    public function optimizeURL($url)
55
    {
56
        return $this->host->optimize($url);
57
    }
58
59
    public function userAgent($string = self::USER_AGENT)
60
    {
61
        $uaParser = new UserAgentParser($string);
62
        $userAgent = $uaParser->match($this->userAgent->userAgents, self::USER_AGENT);
63
        return new UserAgentClient([
64
            self::DIRECTIVE_DISALLOW => $this->userAgent->{self::DIRECTIVE_DISALLOW}[$userAgent],
65
            self::DIRECTIVE_ALLOW => $this->userAgent->{self::DIRECTIVE_ALLOW}[$userAgent],
66
        ], $userAgent, $this->origin, $this->statusCode);
67
    }
68
}
69