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

WebServerFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 7
Bugs 0 Features 1
Metric Value
c 7
b 0
f 1
dl 0
loc 8
rs 9.4285
ccs 3
cts 3
cp 1
cc 2
eloc 4
nc 2
nop 2
crap 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