Completed
Push — master ( 356eb6...32a6a0 )
by Gabriel
07:28
created

DeviceDetector::checkIpad()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 9
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Sinergi\BrowserDetector;
4
5
class DeviceDetector implements DetectorInterface
6
{
7
    /**
8
     * Determine the user's device.
9
     *
10
     * @param Device $device
11
     * @param UserAgent $userAgent
12
     * @return bool
13
     */
14 2
    public static function detect(Device $device, UserAgent $userAgent)
15
    {
16 2
        $device->setName($device::UNKNOWN);
17
18
        return (
19 2
            self::checkIpad($device, $userAgent) ||
20 2
            self::checkIphone($device, $userAgent) ||
21 2
            self::checkWindowsPhone($device, $userAgent)
22 2
        );
23
    }
24
25
    /**
26
     * Determine if the device is iPad.
27
     *
28
     * @param Device $device
29
     * @param UserAgent $userAgent
30
     * @return bool
31
     */
32 2 View Code Duplication
    private static function checkIpad(Device $device, UserAgent $userAgent)
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...
33
    {
34 2
        if (stripos($userAgent->getUserAgentString(), 'ipad') !== false) {
35 1
            $device->setName(Device::IPAD);
36 1
            return true;
37
        }
38
39 2
        return false;
40
    }
41
42
    /**
43
     * Determine if the device is iPhone.
44
     *
45
     * @param Device $device
46
     * @param UserAgent $userAgent
47
     * @return bool
48
     */
49 2 View Code Duplication
    private static function checkIphone(Device $device, UserAgent $userAgent)
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...
50
    {
51 2
        if (stripos($userAgent->getUserAgentString(), 'iphone;') !== false) {
52 1
            $device->setName(Device::IPHONE);
53 1
            return true;
54
        }
55
56 2
        return false;
57
    }
58
59
    /**
60
     * Determine if the device is Windows Phone.
61
     *
62
     * @param Device $device
63
     * @param UserAgent $userAgent
64
     * @return bool
65
     */
66 2 View Code Duplication
    private static function checkWindowsPhone(Device $device, UserAgent $userAgent)
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...
67
    {
68 2
        if (stripos($userAgent->getUserAgentString(), 'Windows Phone') !== false) {
69 1
            if (preg_match('/Microsoft; (Lumia [^)]*)\)/', $userAgent->getUserAgentString(), $matches)) {
70 1
                $device->setName($matches[1]);
71 1
                return true;
72
            }
73
74
            $device->setName($device::WINDOWS_PHONE);
75
            return true;
76
        }
77 2
        return false;
78
    }
79
}
80