PlatformFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 47
ccs 0
cts 14
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
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\Filesystem\Filesystem;
15
16
class PlatformFactory {
17
    /**
18
     * Filesystem.
19
     *
20
     * @var Filesystem
21
     */
22
    protected $filesystem;
23
24
    /**
25
     * Initialiser.
26
     *
27
     * @param Filesystem $filesystem
28
     */
29
    public function __construct(Filesystem $filesystem) {
30
        $this->filesystem = $filesystem;
31
    }
32
33
    /**
34
     * Get the platform with the specified name.
35
     *
36
     * @param string $platformName The name of the platform (retrieved from
37
     *                             PHP_OS).
38
     *
39
     * @return Platform
40
     *
41
     * @throws PlatformException
42
     */
43
    public function getPlatform($platformName) {
44
        switch ($platformName) {
45
            case 'Darwin':
46
            case 'FreeBSD':
47
            case 'Linux':
48
                return new LinuxPlatform($this->filesystem);
49
                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...
50
51
            case 'WINNT':
52
            case 'Windows':
53
                return new WindowsPlatform($this->filesystem);
54
                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...
55
56
            default:
57
                throw new PlatformException(
58
                        sprintf('Unsupported platform %s', PHP_OS),
59
                        PlatformException::CODE_UNKNOWN_PLATFORM);
60
        }
61
    }
62
}
63