Factory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php namespace Nord\Lumen\Search\Formatter;
2
3
use Nord\Lumen\Search\Exceptions\InvalidArgument;
4
use Nord\Lumen\Search\Contracts\Formatter;
5
6
class Factory
7
{
8
    const FORMAT_DATE = 'date';
9
    const FORMAT_LOWERCASE = 'lowercase';
10
11
    /**
12
     * @var array
13
     */
14
    private static $map = [
15
        self::FORMAT_DATE       => 'Nord\Lumen\Search\Formatter\DateFormatter',
16
        self::FORMAT_LOWERCASE  => 'Nord\Lumen\Search\Formatter\LowercaseFormatter',
17
    ];
18
19
20
    /**
21
     * @param string $format
22
     *
23
     * @return Formatter
24
     *
25
     * @throws InvalidArgument
26
     */
27
    public function create($format)
28
    {
29
        if (!isset(self::$map[$format])) {
30
            throw new InvalidArgument("Formatter '$format' is not supported.");
31
        }
32
33
        return new self::$map[$format];
34
    }
35
}
36