RefererParser::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace PragmaRX\Tracker\Support;
4
5
use Snowplow\RefererParser\Parser;
6
7
class RefererParser
8
{
9
    /**
10
     * Referer parser instance.
11
     *
12
     * @var Parser
13
     */
14
    private $parser;
15
16
    /**
17
     * Referer parser instance.
18
     *
19
     * @var \Snowplow\RefererParser\Referer
20
     */
21
    private $referer;
22
23
    /**
24
     * Create a referer parser instance.
25
     *
26
     * @return mixed
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
27
     */
28
    public function __construct(Parser $parser)
29
    {
30
        $this->parser = $parser;
31
    }
32
33
    /**
34
     * Parse a referer.
35
     *
36
     * @return RefererParser
37
     */
38
    public function parse($refererUrl, $pageUrl)
39
    {
40
        $this->setReferer($this->parser->parse($refererUrl, $pageUrl));
41
42
        return $this;
43
    }
44
45
    /**
46
     * Get the search medium.
47
     *
48
     * @return string|null
49
     */
50
    public function getMedium()
51
    {
52
        if ($this->isKnown()) {
53
            return $this->referer->getMedium();
54
        }
55
    }
56
57
    /**
58
     * Get the search source.
59
     *
60
     * @return string|null
61
     */
62
    public function getSource()
63
    {
64
        if ($this->isKnown()) {
65
            return $this->referer->getSource();
66
        }
67
    }
68
69
    /**
70
     * Get the search term.
71
     *
72
     * @return string|null
73
     */
74
    public function getSearchTerm()
75
    {
76
        if ($this->isKnown()) {
77
            return $this->referer->getSearchTerm();
78
        }
79
    }
80
81
    /**
82
     * Check if the referer is knwon.
83
     *
84
     * @return bool
85
     */
86
    public function isKnown()
87
    {
88
        return $this->referer->isKnown();
89
    }
90
91
    /**
92
     * Set the referer.
93
     *
94
     * @param \Snowplow\RefererParser\Referer $referer
95
     *
96
     * @return RefererParser
97
     */
98
    public function setReferer($referer)
99
    {
100
        $this->referer = $referer;
101
102
        return $this;
103
    }
104
}
105