Completed
Push — master ( 5db01c...94622e )
by Gabriel
02:28
created

Browser::getIsChromeFrame()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Sinergi\BrowserDetector;
4
5
/**
6
 * Browser Detection.
7
 */
8
class Browser
9
{
10
    const UNKNOWN = 'unknown';
11
    const VIVALDI = 'Vivaldi';
12
    const OPERA = 'Opera';
13
    const OPERA_MINI = 'Opera Mini';
14
    const WEBTV = 'WebTV';
15
    const IE = 'Internet Explorer';
16
    const POCKET_IE = 'Pocket Internet Explorer';
17
    const KONQUEROR = 'Konqueror';
18
    const ICAB = 'iCab';
19
    const OMNIWEB = 'OmniWeb';
20
    const FIREBIRD = 'Firebird';
21
    const FIREFOX = 'Firefox';
22
    const SEAMONKEY = 'SeaMonkey';
23
    const ICEWEASEL = 'Iceweasel';
24
    const SHIRETOKO = 'Shiretoko';
25
    const MOZILLA = 'Mozilla';
26
    const AMAYA = 'Amaya';
27
    const LYNX = 'Lynx';
28
    const SAFARI = 'Safari';
29
    const CHROME = 'Chrome';
30
    const NAVIGATOR = 'Navigator';
31
    const GOOGLEBOT = 'GoogleBot';
32
    const SLURP = 'Yahoo! Slurp';
33
    const W3CVALIDATOR = 'W3C Validator';
34
    const BLACKBERRY = 'BlackBerry';
35
    const ICECAT = 'IceCat';
36
    const NOKIA_S60 = 'Nokia S60 OSS Browser';
37
    const NOKIA = 'Nokia Browser';
38
    const MSN = 'MSN Browser';
39
    const MSNBOT = 'MSN Bot';
40
    const NETSCAPE_NAVIGATOR = 'Netscape Navigator';
41
    const GALEON = 'Galeon';
42
    const NETPOSITIVE = 'NetPositive';
43
    const PHOENIX = 'Phoenix';
44
    const GSA = 'Google Search Appliance';
45
    const YANDEX = 'Yandex';
46
    const EDGE = 'Edge';
47
48
    const VERSION_UNKNOWN = 'unknown';
49
50
    /**
51
     * @var UserAgent
52
     */
53
    private $userAgent;
54
55
    /**
56
     * @var string
57
     */
58
    private $name;
59
    /**
60
     * @var string
61
     */
62
    private $version;
63
64
    /**
65
     * @var bool
66
     */
67
    private $isRobot = false;
68
69
    /**
70
     * @var bool
71
     */
72
    private $isChromeFrame = false;
73
74
    /**
75
     * @var bool
76
     */
77
    private $isFacebookWebView = false;
78
79
    /**
80
     * @var bool
81
     */
82
    private $isCompatibilityMode = false;
83
84
    /**
85
     * @param null|string|UserAgent $userAgent
86
     *
87
     * @throws \Sinergi\BrowserDetector\InvalidArgumentException
88
     */
89 8 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...
90
    {
91 8
        if ($userAgent instanceof UserAgent) {
92
            $this->setUserAgent($userAgent);
93 8
        } elseif (null === $userAgent || is_string($userAgent)) {
94 8
            $this->setUserAgent(new UserAgent($userAgent));
95 8
        } else {
96
            throw new InvalidArgumentException();
97
        }
98 8
    }
99
100
    /**
101
     * Set the name of the OS.
102
     *
103
     * @param string $name
104
     *
105
     * @return $this
106
     */
107 8
    public function setName($name)
108
    {
109 8
        $this->name = (string)$name;
110
111 8
        return $this;
112
    }
113
114
    /**
115
     * Return the name of the Browser.
116
     *
117
     * @return string
118
     */
119 7
    public function getName()
120
    {
121 7
        if (!isset($this->name)) {
122 7
            BrowserDetector::detect($this, $this->getUserAgent());
123 7
        }
124
125 7
        return $this->name;
126
    }
127
128
    /**
129
     * Check to see if the specific browser is valid.
130
     *
131
     * @param string $name
132
     *
133
     * @return bool
134
     */
135
    public function isBrowser($name)
136
    {
137
        return (0 == strcasecmp($this->getName(), trim($name)));
138
    }
139
140
    /**
141
     * Set the version of the browser.
142
     *
143
     * @param string $version
144
     *
145
     * @return $this
146
     */
147 8
    public function setVersion($version)
148
    {
149 8
        $this->version = (string)$version;
150
151 8
        return $this;
152
    }
153
154
    /**
155
     * The version of the browser.
156
     *
157
     * @return string
158
     */
159 7
    public function getVersion()
160
    {
161 7
        if (!isset($this->name)) {
162
            BrowserDetector::detect($this, $this->getUserAgent());
163
        }
164
165 7
        return (string) $this->version;
166
    }
167
168
    /**
169
     * Set the Browser to be a robot.
170
     *
171
     * @param bool $isRobot
172
     *
173
     * @return $this
174
     */
175
    public function setIsRobot($isRobot)
176
    {
177
        $this->isRobot = (bool)$isRobot;
178
179
        return $this;
180
    }
181
182
    /**
183
     * Is the browser from a robot (ex Slurp,GoogleBot)?
184
     *
185
     * @return bool
186
     */
187
    public function getIsRobot()
188
    {
189
        if (!isset($this->name)) {
190
            BrowserDetector::detect($this, $this->getUserAgent());
191
        }
192
193
        return $this->isRobot;
194
    }
195
196
    /**
197
     * @return bool
198
     */
199
    public function isRobot()
200
    {
201
        return $this->getIsRobot();
202
    }
203
204
    /**
205
     * @param bool $isChromeFrame
206
     *
207
     * @return $this
208
     */
209
    public function setIsChromeFrame($isChromeFrame)
210
    {
211
        $this->isChromeFrame = (bool)$isChromeFrame;
212
213
        return $this;
214
    }
215
216
    /**
217
     * Used to determine if the browser is actually "chromeframe".
218
     *
219
     * @return bool
220
     */
221
    public function getIsChromeFrame()
222
    {
223
        if (!isset($this->name)) {
224
            BrowserDetector::detect($this, $this->getUserAgent());
225
        }
226
227
        return $this->isChromeFrame;
228
    }
229
230
    /**
231
     * @return bool
232
     */
233
    public function isChromeFrame()
234
    {
235
        return $this->getIsChromeFrame();
236
    }
237
238
    /**
239
     * @param bool $isFacebookWebView
240
     *
241
     * @return $this
242
     */
243 1
    public function setIsFacebookWebView($isFacebookWebView)
244
    {
245 1
        $this->isFacebookWebView = (bool) $isFacebookWebView;
246
247 1
        return $this;
248
    }
249
250
    /**
251
     * Used to determine if the browser is actually "facebook".
252
     *
253
     * @return bool
254
     */
255 1
    public function getIsFacebookWebView()
256
    {
257 1
        if (!isset($this->name)) {
258 1
            BrowserDetector::detect($this, $this->getUserAgent());
259 1
        }
260
261 1
        return $this->isFacebookWebView;
262
    }
263
264
    /**
265
     * @return bool
266
     */
267 1
    public function isFacebookWebView()
268
    {
269 1
        return $this->getIsFacebookWebView();
270
    }
271
272
    /**
273
     * @param UserAgent $userAgent
274
     *
275
     * @return $this
276
     */
277 8
    public function setUserAgent(UserAgent $userAgent)
278
    {
279 8
        $this->userAgent = $userAgent;
280
281 8
        return $this;
282
    }
283
284
    /**
285
     * @return UserAgent
286
     */
287 8
    public function getUserAgent()
288
    {
289 8
        return $this->userAgent;
290
    }
291
292
    /**
293
     * @param bool
294
     *
295
     * @return $this
296
     */
297 1
    public function setIsCompatibilityMode($isCompatibilityMode)
298
    {
299 1
        $this->isCompatibilityMode = $isCompatibilityMode;
300
301 1
        return $this;
302
    }
303
304
    /**
305
     * @return bool
306
     */
307
    public function isCompatibilityMode()
308
    {
309
        return $this->isCompatibilityMode;
310
    }
311
312
    /**
313
     * Render pages outside of IE's compatibility mode.
314
     */
315
    public function endCompatibilityMode()
316
    {
317
        header('X-UA-Compatible: IE=edge');
318
    }
319
}
320