FileHandlerFactory::createFileHandler()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Incenteev\ParameterHandler;
4
5
class FileHandlerFactory
6
{
7
    /**
8
     * @var array
9
     */
10
    public static $handlers = [
11
        'yml' => 'YamlHandler',
12
        'php' => 'PhpHandler',
13
    ];
14
15
    /**
16
     * @param string $fileType
17
     *
18
     * @return FileHandlerInterface
19
     */
20
    public static function createFileHandler($fileType)
21
    {
22
        if (!isset(self::$handlers[$fileType])) {
23
            throw new \RuntimeException('Unsupported file type: ' . $fileType);
24
        }
25
26
        $className = '\\Incenteev\\ParameterHandler\\FileHandler\\' . self::$handlers[$fileType];
27
28
        return new $className();
29
    }
30
}
31