Completed
Push — master ( ed845b...38c1c8 )
by Luke
04:37
created

PlatformFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 31
ccs 0
cts 11
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getPlatform() 0 19 6
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