Completed
Push — master ( 0f3a77...fc3715 )
by Elf
02:40
created

Agent::os()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ElfSundae\Agent;
4
5
use ArrayAccess;
6
use JsonSerializable;
7
use Illuminate\Support\Str;
8
use Jenssegers\Agent\Agent as BaseAgent;
9
use Illuminate\Contracts\Support\Jsonable;
10
use Illuminate\Contracts\Support\Arrayable;
11
12
class Agent extends BaseAgent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
13
{
14
    use Concerns\HasAttributes;
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 4
    public function __construct(array $headers = null, $userAgent = null)
20
    {
21 4
        parent::__construct($headers, $userAgent);
22 4
    }
23
24
    /**
25
     * Get the accept language.
26
     *
27
     * @param  string|null  $preferLanguage
28
     * @return string|bool
29
     */
30
    public function language($preferLanguage = null)
31
    {
32
        $languages = $this->languages();
33
34
        if (is_null($preferLanguage)) {
35
            return reset($languages);
36
        }
37
38
        $preferLanguage = strtolower($preferLanguage);
39
40
        foreach ($languages as $lang) {
41
            if (Str::startsWith($lang, $preferLanguage)) {
42
                return true;
43
            }
44
        }
45
46
        return false;
47
    }
48
49
    /**
50
     * Get the operating system (platform) name.
51
     *
52
     * @param  string  $userAgent
53
     * @return string
54
     */
55
    public function os($userAgent = null)
56
    {
57
        return $this->platform($userAgent);
58
    }
59
}
60