Completed
Push — master ( 5fc8fc...78226d )
by James
03:03
created

Factory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 8
c 3
b 0
f 1
lcom 1
cbo 3
dl 0
loc 56
ccs 25
cts 25
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 4
A createWebServer() 0 13 2
A getKnownWebServers() 0 4 1
A createWebProject() 0 5 1
1
<?php
2
3
/**
4
 * This file is, guess what, part of WebHelper.
5
 *
6
 * (c) James <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace JamesRezo\WebHelper;
13
14
use Symfony\Component\Yaml\Yaml;
15
use JamesRezo\WebHelper\WebServer\NullWebServer;
16
use JamesRezo\WebHelper\WebProject\NullWebProject;
17
18
/**
19
 * WebHelper Factory Class.
20
 *
21
 * @author James <[email protected]>
22
 */
23
class Factory
24
{
25
    private $webservers = [];
26
27 29
    public function __construct()
28
    {
29 29
        $file = '';
30
        foreach ([
31 29
            getenv('HOME').'/.config/webhelper/parameters.yml',
32
            __DIR__.'/../app/config/parameters.yml'
33 29
        ] as $file) {
34 29
            if (is_readable($file)) {
35 29
                break;
36
            }
37 29
        }
38
39 29
        if ($file) {
40 29
            $yaml = new Yaml();
41 29
            $config = $yaml->parse(file_get_contents($file));
42 29
            $this->webservers = $config['webservers'];
43 29
        }
44 29
    }
45
46
    /**
47
     * Create a WebServerInterface Object.
48
     *
49
     * @param string $name    a web server software name
50
     * @param string $version a web server software version
51
     *
52
     * @return WebServer\WebServerInterface a WebServer Object
53
     */
54 27
    public function createWebServer($name, $version = '')
55
    {
56 27
        if (in_array($name, $this->getKnownWebServers())) {
57 18
            $webserver = new $this->webservers[$name][0]($version);
58
            $webserver
59 18
                ->setBinaries($this->webservers[$name][1])
60 18
                ->setDetectionParameter($this->webservers[$name][2]);
61
62 18
            return $webserver;
63
        }
64
65 9
        return new NullWebServer($version);
66
    }
67
68 27
    public function getKnownWebServers()
69
    {
70 27
        return array_keys($this->webservers);
71
    }
72
73 2
    public function createWebProject($name, $version = '')
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75 1
        $name = '';
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
76 2
        return new NullWebProject($version);
77
    }
78
}
79