Code Duplication    Length = 35-35 lines in 2 locations

src/Format/Formatter/FormatterFactory.php 1 location

@@ 21-55 (lines=35) @@
18
use Graze\DataFile\Format\JsonFormatInterface;
19
use InvalidArgumentException;
20
21
class FormatterFactory implements FormatterFactoryInterface
22
{
23
    /**
24
     * @param FormatInterface $format
25
     *
26
     * @return FormatterInterface
27
     */
28
    public function getFormatter(FormatInterface $format)
29
    {
30
        switch ($format->getType()) {
31
            case 'csv':
32
                if ($format instanceof CsvFormatInterface) {
33
                    return new CsvFormatter($format);
34
                } else {
35
                    throw new InvalidArgumentException(
36
                        "Format indicates it is csv but does not implement CsvFormatInterface"
37
                    );
38
                }
39
40
            // fallthrough
41
            case 'json':
42
                if ($format instanceof JsonFormatInterface) {
43
                    return new JsonFormatter($format);
44
                } else {
45
                    throw new InvalidArgumentexception(
46
                        "Format indicates it is json but does not implement JsonFormatInterface"
47
                    );
48
                }
49
50
            // fallthrough
51
            default:
52
                throw new InvalidArgumentException("Supplied format: {$format->getType()} is unknown");
53
        }
54
    }
55
}
56

src/Format/Parser/ParserFactory.php 1 location

@@ 12-46 (lines=35) @@
9
use Graze\DataFile\Node\FileNodeInterface;
10
use InvalidArgumentException;
11
12
class ParserFactory implements ParserFactoryInterface
13
{
14
    /**
15
     * @param FormatInterface $format
16
     *
17
     * @return ParserInterface
18
     */
19
    public function getParser(FormatInterface $format)
20
    {
21
        switch ($format->getType()) {
22
            case 'csv':
23
                if ($format instanceof CsvFormatInterface) {
24
                    return new CsvParser($format);
25
                } else {
26
                    throw new InvalidArgumentException(
27
                        "Format indicates it is csv but does not implement CsvFormatInterface"
28
                    );
29
                }
30
31
            // fallthrough
32
            case 'json':
33
                if ($format instanceof JsonFormatInterface) {
34
                    return new JsonParser($format);
35
                } else {
36
                    throw new InvalidArgumentexception(
37
                        "Format indicates it is json but does not implement JsonFormatInterface"
38
                    );
39
                }
40
41
            // fallthrough
42
            default:
43
                throw new InvalidArgumentException("Supplied format: {$format->getType()} is unknown");
44
        }
45
    }
46
}
47