Completed
Pull Request — master (#303)
by Atlas
02:57
created

ConfigFileReaderFactory::createFromFileName()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 4
nop 1
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Hal\Application\Config\File;
4
5
class ConfigFileReaderFactory
6
{
7
    /**
8
     * @param string $filename
9
     *
10
     * @return ConfigFileReaderInterface
11
     */
12
    public static function createFromFileName($filename)
13
    {
14
        if (!is_file($filename) || !is_readable($filename)) {
15
            throw new \InvalidArgumentException("Cannot read configuration file '{$filename}'");
16
        }
17
18
        switch (pathinfo($filename, PATHINFO_EXTENSION)) {
19
            case 'json':
20
                return new ConfigFileReaderJson($filename);
21
            case 'ini':
22
                return new ConfigFileReaderIni($filename);
23
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
24
            default:
25
                throw new \InvalidArgumentException("Unsupported config file format: '$filename'");
26
        }
27
    }
28
}
29