Resolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebStream\Delegate;
3
4
use WebStream\Core\CoreController;
5
use WebStream\Core\CoreService;
6
use WebStream\Core\CoreModel;
7
use WebStream\Core\CoreHelper;
8
use WebStream\Container\Container;
9
use WebStream\IO\File;
10
use WebStream\Exception\Extend\RouterException;
11
use WebStream\Exception\Extend\ResourceNotFoundException;
12
13
/**
14
 * Resolver
15
 * @author Ryuichi TANAKA.
16
 * @since 2012/12/22
17
 * @version 0.7
18
 */
19
class Resolver
20
{
21
    /**
22
     * @var Router ルーティングオブジェクト
23
     */
24
    private $router;
25
26
    /**
27
     * @var Request リクエストオブジェクト
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\Request 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...
28
     */
29
    private $request;
30
31
    /**
32
     * @var Response レスポンスオブジェクト
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\Response 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...
33
     */
34
    private $response;
35
36
    /**
37
     * @var Session セッションオブジェクト
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\Session 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...
38
     */
39
    private $session;
40
41
    /**
42
     * @var Container DIコンテナ
43
     */
44
    private $container;
45
46
    /**
47
     * @var AnnotationContainer アノテーションコンテナ
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\AnnotationContainer 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...
48
     */
49
    private $annotation;
0 ignored issues
show
introduced by
The private property $annotation is not used, and could be removed.
Loading history...
50
51
    /**
52
     * コンストラクタ
53
     * @param Object 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...
54
     */
55
    public function __construct(Container $container)
56
    {
57
        $this->container = $container;
58
        $this->request   = $container->request;
0 ignored issues
show
Documentation Bug introduced by
It seems like $container->request can also be of type string. However, the property $request is declared as type WebStream\Delegate\Request. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Bug Best Practice introduced by
The property request does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
        $this->response  = $container->response;
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...
Documentation Bug introduced by
It seems like $container->response can also be of type string. However, the property $response is declared as type WebStream\Delegate\Response. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
60
        $this->session   = $container->session;
0 ignored issues
show
Bug Best Practice introduced by
The property session does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
Documentation Bug introduced by
It seems like $container->session can also be of type string. However, the property $session is declared as type WebStream\Delegate\Session. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
61
        $this->router    = $container->router;
0 ignored issues
show
Bug Best Practice introduced by
The property router does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
Documentation Bug introduced by
It seems like $container->router can also be of type string. However, the property $router is declared as type WebStream\Delegate\Router. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
62
    }
63
64
    /**
65
     * Controllerを起動する
66
     */
67
    public function runController()
68
    {
69
        // セッションスタート
70
        $this->session->start();
71
        // バッファリング開始
72
        $this->response->start();
73
74
        if ($this->router->controller !== null && $this->router->action !== null) {
75
            $iterator = [];
76
            $file = new File($this->container->applicationInfo->applicationRoot . "/app/controllers");
0 ignored issues
show
Bug Best Practice introduced by
The property applicationInfo does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The property applicationRoot does not exist on string.
Loading history...
77
            if ($file->exists() && $file->isDirectory()) {
78
                $iterator = new \RecursiveIteratorIterator(
79
                    new \RecursiveDirectoryIterator($file->getFilePath()),
80
                    \RecursiveIteratorIterator::LEAVES_ONLY,
81
                    \RecursiveIteratorIterator::CATCH_GET_CHILD // for Permission deny
82
                );
83
            }
84
            foreach ($iterator as $filepath => $fileObject) {
85
                if (strpos($filepath, $this->router->controller . ".php") !== false) {
86
                    include_once $filepath;
87
                }
88
            }
89
            $controllerDelegator = new CoreExecuteDelegator($this->container->coreDelegator->getController(), $this->container);
0 ignored issues
show
Bug Best Practice introduced by
The property coreDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method getController() 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

89
            $controllerDelegator = new CoreExecuteDelegator($this->container->coreDelegator->/** @scrutinizer ignore-call */ getController(), $this->container);

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...
90
            $controllerDelegator->run($this->router->action, [$this->router->params]);
91
        } elseif ($this->router->staticFile !== null) {
92
            $controller = new CoreController();
93
            $controller->inject('coreDelegator', $this->container->coreDelegator)
94
                       ->inject('logger', $this->container->logger);
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...
95
96
            $controller->__callStaticFile($this->router->staticFile);
97
        } else {
98
            $this->response->clean();
99
            $errorMsg = "Failed to resolve the routing: " . $this->request->requestUri;
100
            throw new ResourceNotFoundException($errorMsg);
101
        }
102
103
        $this->response->end();
104
    }
105
106
    /**
107
     * Serviceを起動する
108
     * @return CoreService Serviceオブジェクト
109
     */
110
    public function runService()
111
    {
112
        $service = $this->container->coreDelegator->getService();
0 ignored issues
show
Bug Best Practice introduced by
The property coreDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
113
        $service = $service instanceof CoreService ? new CoreExecuteDelegator($service, $this->container) : $this->runModel();
114
115
        return $service;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $service returns the type WebStream\Delegate\CoreE...ebStream\Core\CoreModel which is incompatible with the documented return type WebStream\Core\CoreService.
Loading history...
116
    }
117
118
    /**
119
     * Modelを起動する
120
     * @return CoreModel Modelオブジェクト
121
     */
122
    public function runModel()
123
    {
124
        $model = $this->container->coreDelegator->getModel();
0 ignored issues
show
Bug Best Practice introduced by
The property coreDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
125
        $model = $model instanceof CoreModel ? new CoreExecuteDelegator($model, $this->container) : $model;
126
127
        return $model;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $model also could return the type WebStream\Delegate\CoreExecuteDelegator which is incompatible with the documented return type WebStream\Core\CoreModel.
Loading history...
128
    }
129
130
    /**
131
     * Viewを起動する
132
     * @return CoreView Viewオブジェクト
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\CoreView 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...
133
     */
134
    public function runView()
135
    {
136
        return new CoreExecuteDelegator($this->container->coreDelegator->getView(), $this->container);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new WebStream\Del...ew(), $this->container) returns the type WebStream\Delegate\CoreExecuteDelegator which is incompatible with the documented return type WebStream\Delegate\CoreView.
Loading history...
Bug Best Practice introduced by
The property coreDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
137
    }
138
139
    /**
140
     * Helperを起動する
141
     * @return CoreHelper Helperオブジェクト
142
     */
143
    public function runHelper()
144
    {
145
        $helper = $this->container->coreDelegator->getHelper();
0 ignored issues
show
Bug Best Practice introduced by
The property coreDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
146
        $helper = $helper instanceof CoreHelper ? new CoreExecuteDelegator($helper, $this->container) : $helper;
147
148
        return $helper;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $helper also could return the type WebStream\Delegate\CoreExecuteDelegator which is incompatible with the documented return type WebStream\Core\CoreHelper.
Loading history...
149
    }
150
}
151