Completed
Push — develop ( 38c1c8...813522 )
by Luke
04:11
created

PlatformFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Moodle component manager.
5
 *
6
 * @author Luke Carrier <[email protected]>
7
 * @copyright 2016 Luke Carrier
8
 * @license GPL-3.0+
9
 */
10
11
namespace ComponentManager\Platform;
12
13
use ComponentManager\Exception\PlatformException;
14
use Symfony\Component\DependencyInjection\Definition;
15
use Symfony\Component\Filesystem\Filesystem;
16
17
class PlatformFactory {
18
    /**
19
     * Filesystem.
20
     *
21
     * @var \Symfony\Component\Filesystem\Filesystem
22
     */
23
    protected $filesystem;
24
25
    /**
26
     * Initialiser.
27
     *
28
     * @param \Symfony\Component\Filesystem\Filesystem $filesystem
29
     */
30
    public function __construct(Filesystem $filesystem) {
31
        $this->filesystem = $filesystem;
32
    }
33
34
    /**
35
     * Get the platform with the specified name.
36
     *
37
     * @param string $platformName The name of the platform (retrieved from
38
     *                             PHP_OS).
39
     *
40
     * @return \ComponentManager\Platform\Platform
0 ignored issues
show
Documentation introduced by
Should the return type not be LinuxPlatform|null|WindowsPlatform?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
41
     *
42
     * @throws \ComponentManager\Exception\PlatformException
43
     */
44
    public function getPlatform($platformName) {
45
        switch ($platformName) {
46
            case 'Darwin':
47
            case 'FreeBSD':
48
            case 'Linux':
49
                return new LinuxPlatform($this->filesystem);
50
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
51
52
            case 'WINNT':
53
            case 'Windows':
54
                return new WindowsPlatform($this->filesystem);
55
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
56
57
            default:
58
                throw new PlatformException(
59
                        sprintf('Unsupported platform %s', PHP_OS),
60
                        PlatformException::CODE_UNKNOWN_PLATFORM);
61
        }
62
    }
63
}
64