Test Failed
Pull Request — master (#85)
by Gabriel
04:03 queued 01:11
created

ScriptedAgent::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.2
cc 4
eloc 7
nc 3
nop 1
1
<?php
2
3
namespace Sinergi\BrowserDetector;
4
5
class ScriptedAgent
6
{
7
    const UNKNOWN = 'unknown';
8
    const GOOGLEBOT = 'Google';
9
    const BAIDU = 'Baidu';
10
    const SLURP = 'Yahoo! Slurp';
11
    const MSNBOT = 'MSN';
12
    const W3CVALIDATOR = 'W3C Validator';
13
    const WKHTMLTOPDF = 'wkhtmltopdf';
14
    const YANDEX = 'Yandex';
15
    const GOOGLEADS = 'Google Ads';
16
    const GLUTENFREE = 'Gluten Free';
17
    const TWITTER = 'Twitter';
18
    const APPLEBOT = 'Apple';
19
    const PAPERLI = 'Paper.li';
20
    const SOCIALRANK = 'SocialRank.io';
21
    const BING = 'Bing';
22
    const AHREFS = 'Ahrefs.com Backlink Research Tool';
23
    const MJ12 = 'Majestic12';
24
    const LIVELAP = 'LiveLap';
25
    const SKYPE = 'Skype';
26
    const ADBEAT = 'AdBeat';
27
    const FACEBOOK = 'Facebook';
28
    const BING_PREVIEW = 'Bing';
29
    const WEBDAV = 'WEBDAV';
30
    const GOOGLEFAVICON = 'Google Favicon';
31
    const METAURI = 'MetaURI';
32
    const TLSPROBE = 'TLSProbe';
33
    const SCOOPIT = 'Scoop.it';
34
    const NETCRAFT = 'Netcraft SSL';
35
    const CURL = 'Curl';
36
    const PYTHON = 'Python';
37
    const GOLANG = 'GoLang';
38
    const PERL = 'Perl';
39
    const VERISIGN = 'Verisign';
40
    const WGET = 'Wget';
41
    const ZGRAB = 'ZGrab';
42
    const JAVA = 'Java';
43
    const SHELLSHOCK = 'ShellShock exploit';
44
    const BROWSERSHOTS = 'BrowserShots';
45
    const WHOIS = 'Who.is';
46
    const MAGEREPORT = 'MageReport';
47
    const ICQ = 'ICQ';
48
    const UBERMETRICS = 'Ubermetrics Technologies';
49
    const PROXIMIC = "Proximic";
50
    const GOOGLEPREVIEW = "Google";
51
52
    const SPIDER = "Spider";
53
    const SURVEY = "Survey";
54
    const EXPLOIT = "Exploit attempt";
55
    const PREVIEW = "Preview";
56
    const TOOL = "Tool";
57
    const GENERIC = "Scripted Agent";
58
    const ADVERTISING = "Ad bots";
59
60
    /**
61
     * @var UserAgent
62
     */
63
    private $userAgent;
64
65
    /**
66
     * @var string
67
     */
68
    private $name;
69
70
    /**
71
     * @var string
72
     */
73
    private $type;
74
75
    /**
76
     * @var string
77
     */
78
    private $url;
79
80 View Code Duplication
    public function __construct($userAgent = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        if ($userAgent instanceof UserAgent) {
83
            $this->setUserAgent($userAgent);
84
        } elseif (null === $userAgent || is_string($userAgent)) {
85
            $this->setUserAgent(new UserAgent($userAgent));
86
        } else {
87
            throw new InvalidArgumentException();
88
        }
89
    }
90
91
    /**
92
     * Set the name of the ScriptedAgent.
93
     *
94
     * @param string $name
95
     *
96
     * @return void
97
     */
98
    public function setName($name)
99
    {
100
        $this->name = (string)$name;
101
    }
102
103
    /**
104
     * Return the name of the ScriptedAgent.
105
     *
106
     * @return string
107
     */
108
    public function getName()
109
    {
110
        if (!isset($this->name)) {
111
            ScriptedAgentDetector::detect($this, $this->getUserAgent());
112
        }
113
114
        return $this->name;
115
    }
116
117
    /**
118
     * Set the type of the ScriptedAgent.
119
     *
120
     * @param string $type
121
     *
122
     * @return void
123
     */
124
    public function setType($type)
125
    {
126
        $this->type = (string)$type;
127
    }
128
129
    /**
130
     * Return the type of the ScriptedAgent.
131
     *
132
     * @return string
133
     */
134
    public function getType()
135
    {
136
        if (!isset($this->type)) {
137
            ScriptedAgentDetector::detect($this, $this->getUserAgent());
138
        }
139
140
        return $this->type;
141
    }
142
143
    /**
144
     * Set the info URL for the ScriptedAgent.
145
     *
146
     * @param string $url
147
     *
148
     * @return void
149
     */
150
    public function setInfoURL($url)
151
    {
152
        $this->url = (string)$url;
153
    }
154
155
    /**
156
     * Return the info URL for the ScriptedAgent.
157
     *
158
     * @return string
159
     */
160
    public function getInfoURL()
161
    {
162
        if (!isset($this->url)) {
163
            ScriptedAgentDetector::detect($this, $this->getUserAgent());
164
        }
165
        return $this->url;
166
    }
167
168
    /**
169
     * @param UserAgent $userAgent
170
     *
171
     * @return void
172
     */
173
    public function setUserAgent(UserAgent $userAgent)
174
    {
175
        $this->userAgent = $userAgent;
176
    }
177
178
    /**
179
     * @return UserAgent
180
     */
181
    public function getUserAgent()
182
    {
183
        return $this->userAgent;
184
    }
185
}
186