Test Failed
Branch new-architecture (b1743d)
by James
03:04
created

WebServerFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 8 2
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\WebServer;
13
14
use Symfony\Component\Yaml\Yaml;
15
16
/**
17
 * WebServer Factory Class.
18
 *
19
 * @author James <[email protected]>
20
 */
21
class WebServerFactory
22
{
23
    private $webservers;
24
25
    public function __construct()
26
    {
27
        $yaml = new Yaml();
28
        $config = $yaml->parse(file_get_contents(__DIR__ . '/../../app/config/parameters.yml'));
29 6
        $this->webservers = $config['webservers'];
30
    }
31
32 6
    /**
33 1
     * Create a WebServerInterface Object.
34 1
     *
35 5
     * @param string $name    a web server software name
36 1
     * @param string $version a web server software version
37 1
     *
38 4
     * @return WebServerInterface a WebServer Object
39 4
     */
40 4
    public function create($name, $version)
41 4
    {
42
        if (in_array($name, array_keys($this->webservers))) {
43 6
            return new $this->webservers[$name]($version);
44
        }
45
46
        return new NullWebServer($version);
47
    }
48
}
49