Application   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 53
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 25

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __destruct() 0 3 1
C shutdownHandler() 0 31 17
A run() 0 26 6
1
<?php
2
namespace WebStream\Core;
3
4
use WebStream\Container\Container;
5
use WebStream\Delegate\Resolver;
6
use WebStream\Exception\ApplicationException;
7
use WebStream\Exception\SystemException;
8
use WebStream\Exception\DelegateException;
9
use WebStream\Module\ServiceLocator;
0 ignored issues
show
Bug introduced by
The type WebStream\Module\ServiceLocator 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
11
/**
12
 * Applicationクラス
13
 * @author Ryuichi Tanaka
14
 * @since 2011/08/19
15
 * @version 0.7
16
 */
17
class Application
18
{
19
    /**
20
     * @var Container DIコンテナ
21
     */
22
    private $container;
23
24
    /**
25
     * アプリケーション共通で使用するクラスを初期化する
26
     * @param Container DIコンテナ
0 ignored issues
show
Documentation Bug introduced by
The doc comment DIコンテナ at position 0 could not be parsed: Unknown type name 'DIコンテナ' at position 0 in DIコンテナ.
Loading history...
27
     */
28
    public function __construct(Container $container)
29
    {
30
        register_shutdown_function([&$this, 'shutdownHandler']);
31
        $this->container = $container;
32
        $this->container->logger->debug("Application start");
0 ignored issues
show
Bug introduced by
The method debug() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $this->container->logger->/** @scrutinizer ignore-call */ 
33
                                  debug("Application start");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property logger does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
    }
34
35
    /**
36
     * アプリケーション終了時の処理
37
     */
38
    public function __destruct()
39
    {
40
        $this->container->logger->debug("Application end");
0 ignored issues
show
Bug Best Practice introduced by
The property logger does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
41
    }
42
43
    /**
44
     * アプリケーションを起動する
45
     */
46
    public function run()
47
    {
48
        try {
49
            $resolver = new Resolver($this->container);
50
            $resolver->runController(); // MVCレイヤへのリクエストの振り分けを実行する
51
        } catch (ApplicationException $e) {
52
            // 内部例外の内、ハンドリングを許可している例外
53
            try {
54
                $this->container->logger->error($e->getExceptionAsString());
0 ignored issues
show
Bug Best Practice introduced by
The property logger does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
                $isHandled = false;
56
                if ($e instanceof DelegateException) {
57
                    $isHandled = $e->isHandled();
58
                    $e = $e->getOriginException();
59
                }
60
                if (!$isHandled) {
61
                    $this->container->response->move($e->getCode());
0 ignored issues
show
Bug introduced by
The method move() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
                    $this->container->response->/** @scrutinizer ignore-call */ 
62
                                                move($e->getCode());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property response does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
62
                }
63
            } catch (\Exception $e) {
64
                // 開発者由来の例外は全て500
65
                $this->container->logger->fatal($e->getExceptionAsString());
0 ignored issues
show
Bug introduced by
The method getExceptionAsString() does not exist on Exception. It seems like you code against a sub-type of Exception such as WebStream\Exception\SystemException or WebStream\Exception\ApplicationException. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
                $this->container->logger->fatal($e->/** @scrutinizer ignore-call */ getExceptionAsString());
Loading history...
66
                $this->container->response->move(500);
67
            }
68
        } catch (SystemException $e) {
69
            // 内部例外の内、ハンドリング不許可の例外
70
            $this->container->logger->fatal($e->getExceptionAsString());
71
            $this->container->response->move($e->getCode());
72
        }
73
    }
74
75
    /**
76
     * 例外捕捉不可な異常時のアプリケーション終了処理
77
     */
78
    public function shutdownHandler()
79
    {
80
        if ($error = error_get_last()) {
81
            $errorMsg = $error['message'] . " " . $error['file'] . "(" . $error['line'] . ")";
82
            switch ($error['type']) {
83
                case E_ERROR:
84
                case E_CORE_ERROR:
85
                case E_COMPILE_ERROR:
86
                case E_USER_ERROR:
87
                case E_RECOVERABLE_ERROR:
88
                    $this->container->logger->fatal($errorMsg);
0 ignored issues
show
Bug Best Practice introduced by
The property logger does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
89
                    $this->container->logger->enableDirectWrite();
90
                    $this->container->response->move(500);
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
91
                    break;
92
                case E_PARSE:
93
                    $this->container->logger->error($errorMsg);
94
                    $this->container->logger->enableDirectWrite();
95
                    $this->container->response->move(500);
96
                    break;
97
                case E_WARNING:
98
                case E_CORE_WARNING:
99
                case E_COMPILE_WARNING:
100
                case E_USER_WARNING:
101
                case E_STRICT:
102
                case E_NOTICE:
103
                case E_USER_NOTICE:
104
                case E_DEPRECATED:
105
                case E_USER_DEPRECATED:
106
                    $this->container->logger->warn($errorMsg);
107
                    $this->container->logger->enableDirectWrite();
108
                    break;
109
            }
110
        }
111
    }
112
}
113