Completed
Push — master ( c5a357...79cf75 )
by Mehmet
07:41
created

ParserFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createParser() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Selami\Entity\Parser;
6
7
class ParserFactory
8
{
9
    /**
10
     * @var array
11
     */
12
    protected static $validParsers = [
13
        'ini'   => ConfigIni::class,
14
        'json'  => Json::class,
15
        'yaml'  => Yaml::class,
16
        'xml'   => Xml::class,
17
        'php'   => PhpArray::class
18
    ];
19
    public static function createParser(string $parserType)
20
    {
21
        if (!in_array($parserType, self::$validParsers, true)) {
22
            $message = sprintf(
23
                'Invalid parser type: %s. Valid types are case sensitive and possible values are: %s',
24
                $parserType,
25
                implode(', ', array_keys(self::$validParsers))
26
            );
27
            throw new UnexpectedValueException($message);
28
        }
29
        return new self::$validParsers[$parserType]();
30
    }
31
}
32