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

WebServerFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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