Test Failed
Pull Request — master (#76)
by
unknown
02:35
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
/**
6
 * Browser Detection.
7
 */
8
class ScriptedAgent
9
{
10
    const UNKNOWN = 'unknown';
11
    const GOOGLEBOT = 'Google';
12
    const BAIDU = 'Baidu';
13
    const SLURP = 'Yahoo! Slurp';
14
    const MSNBOT = 'MSN';
15
    const W3CVALIDATOR = 'W3C Validator';
16
    const WKHTMLTOPDF = 'wkhtmltopdf';
17
    const YANDEX = 'Yandex';
18
    const GOOGLEADS = 'Google Ads';
19
    const GLUTENFREE = 'Gluten Free';
20
    const TWITTER = 'Twitter';
21
    const APPLEBOT = 'Apple';
22
    const PAPERLI = 'Paper.li';
23
    const SOCIALRANK = 'SocialRank.io';
24
    const BING = 'Bing';
25
    const AHREFS = 'Ahrefs.com Backlink Research Tool';
26
    const MJ12 = 'Majestic12';
27
    const LIVELAP = 'LiveLap';
28
    const SKYPE = 'Skype';
29
    const ADBEAT = 'AdBeat';
30
    const FACEBOOK = 'Facebook';
31
    const BING_PREVIEW = 'Bing';
32
    const WEBDAV = 'WEBDAV';
33
    const GOOGLEFAVICON = 'Google Favicon';
34
    const METAURI = 'MetaURI';
35
    const TLSPROBE = 'TLSProbe';
36
    const SCOOPIT = 'Scoop.it';
37
    const NETCRAFT = 'Netcraft SSL';
38
    const CURL = 'Curl';
39
    const PYTHON = 'Python';
40
    const GOLANG = 'GoLang';
41
    const PERL = 'Perl';
42
    const VERISIGN = 'Verisign';
43
    const WGET = 'Wget';
44
    const ZGRAB = 'ZGrab';
45
    const JAVA = 'Java';
46
    const SHELLSHOCK = 'ShellShock exploit';
47
    const BROWSERSHOTS = 'BrowserShots';
48
    const WHOIS = 'Who.is';
49
    const MAGEREPORT = 'MageReport';
50
    const ICQ = 'ICQ';
51
    const UBERMETRICS = 'Ubermetrics Technologies';
52
    const PROXIMIC = "Proximic";
53
    const GOOGLEPREVIEW = "Google";
54
55
    const SPIDER = "Spider";
56
    const SURVEY = "Survey";
57
    const EXPLOIT = "Exploit attempt";
58
    const PREVIEW = "Preview";
59
    const TOOL = "Tool";
60
    const GENERIC = "Scripted Agent";
61
    const ADVERTISING = "Ad bots";
62
63
    /**
64
     * @var UserAgent
65
     */
66
    private $userAgent;
67
68
    /**
69
     * @var string
70
     */
71
    private $name;
72
73
    /**
74
     * @var string
75
     */
76
    private $type;
77
78
    /**
79
     * @var string
80
     */
81
    private $url;
82
83 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...
84
    {
85
        if ($userAgent instanceof UserAgent) {
86
            $this->setUserAgent($userAgent);
87
        } elseif (null === $userAgent || is_string($userAgent)) {
88
            $this->setUserAgent(new UserAgent($userAgent));
89
        } else {
90
            throw new InvalidArgumentException();
91
        }
92
    }
93
94
    /**
95
     * Set the name of the ScriptedAgent.
96
     *
97
     * @param string $name
98
     *
99
     * @return void
100
     */
101
    public function setName($name)
102
    {
103
        $this->name = (string)$name;
104
    }
105
106
    /**
107
     * Return the name of the ScriptedAgent.
108
     *
109
     * @return string
110
     */
111
    public function getName()
112
    {
113
        if (!isset($this->name)) {
114
            ScriptedAgentDetector::detect($this, $this->getUserAgent());
115
        }
116
117
        return $this->name;
118
    }
119
120
    /**
121
     * Set the type of the ScriptedAgent.
122
     *
123
     * @param string $type
124
     *
125
     * @return void
126
     */
127
    public function setType($type)
128
    {
129
        $this->type = (string)$type;
130
    }
131
132
    /**
133
     * Return the type of the ScriptedAgent.
134
     *
135
     * @return string
136
     */
137
    public function getType()
138
    {
139
        if (!isset($this->type)) {
140
            ScriptedAgentDetector::detect($this, $this->getUserAgent());
141
        }
142
143
        return $this->type;
144
    }
145
146
    /**
147
     * Set the info URL for the ScriptedAgent.
148
     *
149
     * @param string $url
150
     *
151
     * @return void
152
     */
153
    public function setInfoURL($url)
154
    {
155
        $this->url = (string)$url;
156
    }
157
158
    /**
159
     * Return the info URL for the ScriptedAgent.
160
     *
161
     * @return string
162
     */
163
    public function getInfoURL()
164
    {
165
        if (!isset($this->url)) {
166
            ScriptedAgentDetector::detect($this, $this->getUserAgent());
167
        }
168
        return $this->url;
169
    }
170
171
    /**
172
     * @param UserAgent $userAgent
173
     *
174
     * @return void
175
     */
176
    public function setUserAgent(UserAgent $userAgent)
177
    {
178
        $this->userAgent = $userAgent;
179
    }
180
181
    /**
182
     * @return UserAgent
183
     */
184
    public function getUserAgent()
185
    {
186
        return $this->userAgent;
187
    }
188
189
190
}
191
192
193
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...