OperatingSystemTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getOperatingSystem() 0 15 5
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