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

CleanParamClient::export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace vipnytt\RobotsTxtParser\Client\Directives;
3
4
/**
5
 * Class CleanParamClient
6
 *
7
 * @see https://github.com/VIPnytt/RobotsTxtParser/blob/master/docs/methods/CleanParamClient.md for documentation
8
 * @package vipnytt\RobotsTxtParser\Client\Directives
9
 */
10
class CleanParamClient extends InlineCleanParamClient
11
{
12
    /**
13
     * Common dynamic uri parameters
14
     * @var string[]
15
     */
16
    protected $commonParam = [
17
        'popup',
18
        'ref',
19
        'token',
20
        'utm_medium',
21
        'utm_source',
22
    ];
23
24
    /**
25
     * CleanParamClient constructor.
26
     *
27
     * @param string[][] $cleanParam
28
     */
29
    public function __construct(array $cleanParam)
30
    {
31
        parent::__construct($cleanParam);
32
    }
33
34
    /**
35
     * Has robots.txt defined dynamic or common dynamic parameters check
36
     *
37
     * @param string $uri
38
     * @param string[] $customParam
39
     * @return string[]
40
     */
41
    public function detectWithCommon($uri, array $customParam = [])
42
    {
43
        $pairs = array_merge_recursive(
44
            $this->cleanParam,
45
            $this->appendPath($this->commonParam),
46
            $this->appendPath($customParam)
47
        );
48
        return $this->parse($uri, $pairs);
49
    }
50
51
    /**
52
     * Convert param list to an valid Clean-param list
53
     *
54
     * @param string[] $parameters
55
     * @return array
56
     */
57
    private function appendPath(array $parameters)
58
    {
59
        $result = [];
60
        foreach ($parameters as $parameter) {
61
            $result[$parameter] = ['/'];
62
        }
63
        return $result;
64
    }
65
}
66