Completed
Push — master ( 902e66...0cbd7a )
by Jan-Petter
02:44
created

InlineCleanParamClient::parse()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 8.8571
cc 5
eloc 11
nc 3
nop 2
1
<?php
2
namespace vipnytt\RobotsTxtParser\Client\Directives;
3
4
/**
5
 * Class InlineCleanParamClient
6
 *
7
 * @see https://github.com/VIPnytt/RobotsTxtParser/blob/master/docs/methods/InlineCleanParamClient.md for documentation
8
 * @package vipnytt\RobotsTxtParser\Client\Directives
9
 */
10
class InlineCleanParamClient implements ClientInterface
11
{
12
    use DirectiveClientCommons;
13
14
    /**
15
     * Clean-param
16
     * @var string[][]
17
     */
18
    protected $cleanParam = [];
19
20
    /**
21
     * CleanParamClient constructor.
22
     *
23
     * @param string[][] $cleanParam
24
     */
25
    public function __construct(array $cleanParam)
26
    {
27
        $this->cleanParam = $cleanParam;
28
    }
29
30
    /**
31
     * Export
32
     *
33
     * @return string[][]
34
     */
35
    public function export()
36
    {
37
        return $this->cleanParam;
38
    }
39
40
    /**
41
     * Detect dynamic parameters
42
     *
43
     * @param  string $uri
44
     * @return string[]
45
     */
46
    public function detect($uri)
47
    {
48
        return $this->parse($uri, $this->cleanParam);
49
    }
50
51
    /**
52
     * Parse uri and return detected parameters
53
     *
54
     * @param string $uri
55
     * @param array $pairs
56
     * @return string[]
57
     */
58
    protected function parse($uri, array $pairs)
59
    {
60
        $result = [];
61
        foreach ($pairs as $param => $paths) {
62
            if (
63
                (
64
                    strpos($uri, "?$param=") ||
65
                    strpos($uri, "&$param=")
66
                ) &&
67
                $this->checkPaths($uri, $paths)
68
            ) {
69
                $result[] = $param;
70
            }
71
        }
72
        sort($result);
73
        return $result;
74
    }
75
}
76