Completed
Branch master (e6372b)
by Gareth
26:10 queued 11:01
created

OperatingSystemTrait::getOperatingSystem()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 8.8571
cc 5
eloc 11
nc 5
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
    protected function getOperatingSystem(): String
12
    {
13
        if (isset($this->options["operatingSystem"])) {
14
            return $this->options["operatingSystem"];
0 ignored issues
show
Bug introduced by
The property options does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
        }
16
        $uname = strtolower(php_uname());
17
        if (strpos($uname, "darwin") !== false) {
18
            return "osx";
19
        } elseif (strpos($uname, "win") !== false) {
20
            return "windows";
21
        } elseif (strpos($uname, "linux") !== false) {
22
            return "linux";
23
        }
24
        throw new UnknownOperatingSystemException("Unknown operating system {$uname}");
25
    }
26
}
27