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

ConfigFileReaderFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B createFromFileName() 0 16 5
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