OS::isBSD()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/*
3
 * This file is part of the "andrey-helldar/support" project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Andrey Helldar <[email protected]>
9
 *
10
 * @copyright 2021 Andrey Helldar
11
 *
12
 * @license MIT
13
 *
14
 * @see https://github.com/andrey-helldar/support
15
 */
16
17
namespace Helldar\Support\Helpers;
18
19
use Helldar\Support\Facades\Helpers\Str as StrHelper;
20
21
/**
22
 * @see https://www.php.net/manual/ru/reserved.constants.php
23
 */
24
class OS
25
{
26 2
    public function isUnix(): bool
27
    {
28 2
        return ! $this->isWindows() && ! $this->isUnknown();
29
    }
30
31 4
    public function isWindows(): bool
32
    {
33 4
        return $this->family() === 'windows';
34
    }
35
36 2
    public function isBSD(): bool
37
    {
38 2
        return $this->family() === 'bsd';
39
    }
40
41 2
    public function isDarwin(): bool
42
    {
43 2
        return $this->family() === 'darwin';
44
    }
45
46 2
    public function isSolaris(): bool
47
    {
48 2
        return $this->family() === 'solaris';
49
    }
50
51 2
    public function isLinux(): bool
52
    {
53 2
        return $this->family() === 'linux';
54
    }
55
56 4
    public function isUnknown(): bool
57
    {
58 4
        return $this->family() === 'unknown';
59
    }
60
61 16
    public function family(bool $lower = true): string
62
    {
63 16
        $family = version_compare(PHP_VERSION, '7.2', '<') ? PHP_OS : PHP_OS_FAMILY;
64
65 16
        return $lower ? StrHelper::lower($family) : $family;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $lower ? Helldar\...ower($family) : $family could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
66
    }
67
}
68