WriterFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 24
ccs 0
cts 7
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromName() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/qrcode-library project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\QrCode\Factory;
13
14
use Da\QrCode\Contracts\WriterInterface;
15
use Da\QrCode\Exception\UnknownWriterException;
16
use Da\QrCode\Writer\EpsWriter;
17
use Da\QrCode\Writer\JpgWriter;
18
use Da\QrCode\Writer\PngWriter;
19
use Da\QrCode\Writer\SvgWriter;
20
21
class WriterFactory
22
{
23
    protected static $map = [
24
        'eps' => EpsWriter::class,
25
        'jpg' => JpgWriter::class,
26
        'png' => PngWriter::class,
27
        'svg' => SvgWriter::class
28
    ];
29
30
    /**
31
     * @param string $name
32
     *
33
     * @throws UnknownWriterException
34
     * @return WriterInterface
35
     */
36
    public static function fromName(string $name): WriterInterface
37
    {
38
        if (!array_key_exists($name, self::$map)) {
39
            throw new UnknownWriterException(sprintf('Unknown writer name "%s"', $name));
40
        }
41
42
        return new self::$map[$name];
43
    }
44
}
45