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

Parser::optimizeURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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