OperatingSystemTrait::getOperatingSystem()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 11
nc 5
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace GarethEllis\Tldr\Fetcher;
5
6
use GarethEllis\Tldr\Fetcher\Exception\PageNotFoundException;
7
use GarethEllis\Tldr\Fetcher\Exception\UnknownOperatingSystemException;
8
9
trait OperatingSystemTrait
10
{
11
    /**
12
     * @var array
13
     */
14
    private $options;
15
16
    protected function getOperatingSystem(array $options): String
17
    {
18
        if (isset($options["operatingSystem"])) {
19
            return $options["operatingSystem"];
20
        }
21
        $uname = strtolower(php_uname());
22
        if (strpos($uname, "darwin") !== false) {
23
            return "osx";
24
        } elseif (strpos($uname, "win") !== false) {
25
            return "windows";
26
        } elseif (strpos($uname, "linux") !== false) {
27
            return "linux";
28
        }
29
        throw new UnknownOperatingSystemException("Unknown operating system {$uname}");
30
    }
31
}
32