Passed
Push — feature/0.7.0 ( 49f0a6...c2b907 )
by Ryuichi
44:54
created

CoreView   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 133
rs 10
c 0
b 0
f 0
wmc 19

10 Methods

Rating   Name   Duplication   Size   Complexity  
B draw() 0 16 5
A __customAnnotation() 0 2 1
B __file() 0 11 5
A __initialize() 0 3 1
A outputHeader() 0 3 1
A __destruct() 0 3 1
A templateCache() 0 4 2
A display() 0 3 1
A download() 0 4 1
A setTemplateEngine() 0 3 1
1
<?php
2
namespace WebStream\Core;
3
4
use WebStream\Annotation\Attributes\Filter;
5
use WebStream\Annotation\Base\IAnnotatable;
6
use WebStream\Container\Container;
7
use WebStream\DI\Injector;
8
use WebStream\Template\ITemplateEngine;
9
use WebStream\Util\CommonUtils;
10
11
/**
12
 * CoreViewクラス
13
 * @author Ryuichi TANAKA.
14
 * @since 2011/09/12
15
 * @version 0.7
16
 */
17
class CoreView implements CoreInterface, IAnnotatable
18
{
19
    use Injector, CommonUtils;
20
21
    /**
22
     * @var Container 依存コンテナ
23
     */
24
    private $container;
25
26
    /**
27
     * @var ITemplateEngine テンプレートエンジン
28
     */
29
    private $templateEngine;
30
31
    /**
32
     * @var LoggerAdapter ロガー
0 ignored issues
show
Bug introduced by
The type WebStream\Core\LoggerAdapter 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 $logger;
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function __destruct()
40
    {
41
        $this->logger->debug("View end.");
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     * @Filter(type="initialize")
47
     */
48
    public function __initialize(Container $container)
49
    {
50
        $this->container = $container;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function __customAnnotation(array $annotation)
57
    {
58
    }
59
60
    /**
61
     * テンプレートエンジンを設定する
62
     * @param ITemplateEngine テンプレートエンジン
63
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment テンプレートエンジン at position 0 could not be parsed: Unknown type name 'テンプレートエンジン' at position 0 in テンプレートエンジン.
Loading history...
64
    public function setTemplateEngine(ITemplateEngine $templateEngine = null)
65
    {
66
        $this->templateEngine = $templateEngine;
67
    }
68
69
    /**
70
     * テンプレートを描画する
71
     * @param array<string> パラメータ
72
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment パラメータ at position 0 could not be parsed: Unknown type name 'パラメータ' at position 0 in パラメータ.
Loading history...
73
    public function draw(array $params)
74
    {
75
        $mimeType = $params["mimeType"];
76
        $this->outputHeader($mimeType);
77
78
        // HTML,XML以外はテンプレートを使用しない
79
        if ($mimeType !== 'html' && $mimeType !== 'xml') {
80
            $this->logger->debug("Only html or xml draw view template.");
81
82
            return;
83
        }
84
85
        if ($this->templateEngine !== null) {
86
            $this->templateEngine->render($params);
87
            if ($this->templateEngine instanceof \WebStream\Template\Basic) {
88
                $this->templateEngine->renderHelper($params);
89
            }
90
        }
91
    }
92
93
    /**
94
     * テンプレートキャッシュを作成する
95
     * @param string テンプレートファイルパス
96
     * @param string 保存データ
97
     * @param integer 有効期限
98
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment テンプレートファイルパス at position 0 could not be parsed: Unknown type name 'テンプレートファイルパス' at position 0 in テンプレートファイルパス.
Loading history...
99
    public function templateCache($filepath, $cacheData, $cacheTime)
100
    {
101
        if ($this->templateEngine instanceof \WebStream\Template\Basic) {
102
            $this->templateEngine->cache($filepath, $cacheData, $cacheTime);
103
        }
104
    }
105
106
    /**
107
     * 共通ヘッダを出力する
108
     * @param String ファイルタイプ
109
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ファイルタイプ at position 0 could not be parsed: Unknown type name 'ファイルタイプ' at position 0 in ファイルタイプ.
Loading history...
110
    private function outputHeader($type)
111
    {
112
        $this->container->response->setType($type);
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...
Bug introduced by
The method setType() 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

112
        $this->container->response->/** @scrutinizer ignore-call */ 
113
                                    setType($type);

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...
113
    }
114
115
    /**
116
     * publicディレクトリにある静的ファイルを表示する
117
     * @param String ファイルパス
118
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ファイルパス at position 0 could not be parsed: Unknown type name 'ファイルパス' at position 0 in ファイルパス.
Loading history...
119
    final public function __file($filepath)
120
    {
121
        $publicDir = $this->container->applicationInfo->publicDir;
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 publicDir does not exist on string.
Loading history...
122
        if (preg_match('/\/views\/' . $publicDir . '\/img\/.+\.(?:jp(?:e|)g|png|bmp|(?:tif|gi)f)$/i', $filepath) ||
123
            preg_match('/\/views\/' . $publicDir . '\/css\/.+\.css$/i', $filepath) ||
124
            preg_match('/\/views\/' . $publicDir . '\/js\/.+\.js$/i', $filepath)) { // 画像,css,jsの場合
125
            $this->display($filepath);
126
        } elseif (preg_match('/\/views\/' . $publicDir . '\/file\/.+$/i', $filepath)) { // それ以外のファイル
127
            $this->download($filepath);
128
        } else { // 全てのファイル
129
            $this->display($filepath);
130
        }
131
    }
132
133
    /**
134
     * 画像、CSS、JavaScriptファイルを表示する
135
     * @param string ファイルパス
136
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ファイルパス at position 0 could not be parsed: Unknown type name 'ファイルパス' at position 0 in ファイルパス.
Loading history...
137
    final private function display($filename)
138
    {
139
        $this->container->response->displayFile($filename);
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...
140
    }
141
142
    /**
143
     * ファイルをダウンロードする
144
     * @param string ファイルパス
145
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment ファイルパス at position 0 could not be parsed: Unknown type name 'ファイルパス' at position 0 in ファイルパス.
Loading history...
146
    final private function download($filename)
147
    {
148
        $userAgent = $this->container->request->userAgent();
0 ignored issues
show
Bug introduced by
The method userAgent() 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

148
        /** @scrutinizer ignore-call */ 
149
        $userAgent = $this->container->request->userAgent();

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 request does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
149
        $this->container->response->downloadFile($filename, $userAgent);
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...
150
    }
151
}
152