Completed
Branch develop (e3b860)
by Luke
13:48
created

PlatformFactory::getPlatform()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 8.8571
cc 6
eloc 15
nc 6
nop 1
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
16
class PlatformFactory {
17
    /**
18
     * Get the platform with the specified name.
19
     *
20
     * @param string $platformName The name of the platform (retrieved from
21
     *                             PHP_OS).
22
     *
23
     * @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...
24
     *
25
     * @throws \ComponentManager\Exception\PlatformException
26
     */
27
    public function getPlatform($platformName) {
28
        switch ($platformName) {
29
            case 'Darwin':
30
            case 'FreeBSD':
31
            case 'Linux':
32
                return new LinuxPlatform();
33
                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...
34
35
            case 'WINNT':
36
            case 'Windows':
37
                return new WindowsPlatform();
38
                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...
39
40
            default:
41
                throw new PlatformException(
42
                        sprintf('Unsupported platform %s', PHP_OS),
43
                        PlatformException::CODE_UNKNOWN_PLATFORM);
44
        }
45
    }
46
}
47