Passed
Push — master ( e297c9...6645eb )
by Dawid
02:47
created

ConfigException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A forUnreadableDirectory() 0 3 1
A forInvalidValue() 0 3 1
A forInvalidSource() 0 6 1
A forUnsupportedFileType() 0 6 1
1
<?php declare(strict_types=1);
2
3
namespace Igni\Application\Exception;
4
5
use Igni\Application\Config;
6
7
class ConfigException extends ApplicationException
8
{
9
    public static function forInvalidValue($key, $expectedType, $givenType): ConfigException
10
    {
11
        return new self("Invalid configuration at $key, expected $expectedType, given $givenType");
12
    }
13
14
    public static function forUnreadableDirectory(string $dir)
15
    {
16
        return new self("Could not read configuration dir $dir, make sure that dir exists and process has read access to it.");
17
    }
18
19
    public static function forUnsupportedFileType($path): ConfigException
20
    {
21
        return new self(sprintf(
22
            '%s does not does not recognize the file: %s',
23
            Config::class,
24
            $path
25
        ));
26
    }
27
28
    public static function forInvalidSource($source): ConfigException
29
    {
30
        return new self(sprintf(
31
            '%s::from($source) expects argument to be either string or array %s passed',
32
            Config::class,
33
            gettype($source)
34
        ));
35
    }
36
}
37