Completed
Push — master ( 927462...25b62e )
by Derek Stephen
01:54
created

Init::loggerCheck()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bone\Controller;
4
5
use Barnacle\Container;
0 ignored issues
show
Bug introduced by
The type Barnacle\Container 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...
6
use Bone\I18n\I18nAwareInterface;
0 ignored issues
show
Bug introduced by
The type Bone\I18n\I18nAwareInterface 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...
7
use Bone\Controller\Controller;
8
use Bone\View\ViewEngine;
0 ignored issues
show
Bug introduced by
The type Bone\View\ViewEngine 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...
9
use Bone\Log\LoggerAwareInterface;
0 ignored issues
show
Bug introduced by
The type Bone\Log\LoggerAwareInterface 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...
10
use Bone\Server\SessionAwareInterface;
0 ignored issues
show
Bug introduced by
The type Bone\Server\SessionAwareInterface 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 Bone\Server\SiteConfig;
0 ignored issues
show
Bug introduced by
The type Bone\Server\SiteConfig 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...
12
use Bone\Server\SiteConfigAwareInterface;
0 ignored issues
show
Bug introduced by
The type Bone\Server\SiteConfigAwareInterface 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...
13
use Bone\View\ViewAwareInterface;
0 ignored issues
show
Bug introduced by
The type Bone\View\ViewAwareInterface 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...
14
use Del\SessionManager;
0 ignored issues
show
Bug introduced by
The type Del\SessionManager 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...
15
use Laminas\I18n\Translator\Translator;
0 ignored issues
show
Bug introduced by
The type Laminas\I18n\Translator\Translator 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...
16
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface 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...
17
18
class Init
19
{
20
    /**
21
     * @param Controller $controller
22
     * @param Container $container
23
     * @return Controller
24
     */
25
    public static function controller(Controller $controller, Container $container): Controller
26
    {
27
        self::i18nCheck($controller, $container);
28
        self::viewCheck($controller, $container);
29
        self::siteConfigCheck($controller, $container);
30
        self::sessionCheck($controller, $container);
31
        self::loggerCheck($controller, $container);
32
33
        return $controller;
34
    }
35
36
    /**
37
     * @param \Bone\Controller\Controller $controller
38
     * @param Container $container
39
     */
40
    private static function i18nCheck(Controller $controller, Container $container): void
41
    {
42
        if ($controller instanceof I18nAwareInterface) {
43
            $controller->setTranslator($container->get(Translator::class));
44
        }
45
    }
46
47
    /**
48
     * @param \Bone\Controller\Controller $controller
49
     * @param Container $container
50
     */
51
    private static function viewCheck(Controller $controller, Container $container): void
52
    {
53
        if ($controller instanceof ViewAwareInterface) {
54
            $controller->setView($container->get(ViewEngine::class));
55
        }
56
    }
57
58
    /**
59
     * @param \Bone\Controller\Controller $controller
60
     * @param Container $container
61
     */
62
    private static function siteConfigCheck(Controller $controller, Container $container): void
63
    {
64
        if ($controller instanceof SiteConfigAwareInterface) {
65
            $controller->setSiteConfig($container->get(SiteConfig::class));
66
        }
67
    }
68
69
    /**
70
     * @param \Bone\Controller\Controller $controller
71
     * @param Container $container
72
     */
73
    private static function sessionCheck(Controller $controller, Container $container): void
74
    {
75
        if ($controller instanceof SessionAwareInterface) {
76
            $controller->setSession($container->get(SessionManager::class));
77
        }
78
    }
79
80
    /**
81
     * @param \Bone\Controller\Controller $controller
82
     * @param Container $container
83
     */
84
    private static function loggerCheck(Controller $controller, Container $container): void
85
    {
86
        if ($controller instanceof LoggerAwareInterface) {
87
            $channel = $controller->getChannel();
88
            $loggers = $container->get(LoggerInterface::class);
89
            $logger = in_array($channel, $loggers) ? $loggers['channel'] : $loggers['default'];
90
            $controller->setLogger($logger);
91
        }
92
    }
93
}