Passed
Push — master ( ecaff5...98df6c )
by Joao
13:38 queued 15s
created

Psr11::environment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 18
rs 9.8333
cc 2
nc 2
nop 0
1
<?php
2
3
namespace RestTemplate;
4
5
use ByJG\Cache\Psr16\FileSystemCacheEngine;
6
use ByJG\Cache\Psr16\NoCacheEngine;
7
use ByJG\Config\Container;
8
use ByJG\Config\Definition;
9
use ByJG\Config\Exception\ConfigNotFoundException;
10
use ByJG\Config\Exception\EnvironmentException;
0 ignored issues
show
Bug introduced by
The type ByJG\Config\Exception\EnvironmentException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Psr\SimpleCache\InvalidArgumentException;
12
13
class Psr11
14
{
15
    private static $definition = null;
16
    private static $container = null;
17
18
    /**
19
     * @param string $env
20
     * @return Container
21
     * @throws ConfigNotFoundException
22
     * @throws EnvironmentException
23
     * @throws InvalidArgumentException
24
     */
25
    public static function container($env = null)
26
    {
27
        if (is_null(self::$container)) {
28
            self::$container = self::environment()->build($env);
29
        }
30
31
        return self::$container;
32
    }
33
34
    /**
35
     * @return Definition
36
     * @throws EnvironmentException
37
     */
38
    public static function environment()
39
    {
40
        if (is_null(self::$definition)) {
41
            self::$definition = (new Definition())
42
                ->addConfig('dev')
43
                ->addConfig('test')
44
                    ->inheritFrom('dev')
45
                ->addConfig('staging')
46
                    ->inheritFrom('dev')
47
                ->addConfig('prod')
48
                    ->inheritFrom('staging')
49
                    ->inheritFrom('dev')
50
                ->setCache(['dev', 'test'], new NoCacheEngine())
51
                ->setCache(['prod', 'staging'], new FileSystemCacheEngine())
52
            ;
53
        }
54
55
        return self::$definition;
56
    }
57
}
58