Passed
Push — 6.0 ( 85e367...f409e2 )
by
unknown
02:33
created

LoadLangPack::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 19
rs 10
c 0
b 0
f 0
1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\middleware;
14
15
use Closure;
16
use think\App;
17
use think\Lang;
18
use think\Request;
19
20
class LoadLangPack
1 ignored issue
show
Coding Style introduced by
Missing class doc comment
Loading history...
21
{
22
23
    /** @var Lang */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
24
    protected $lang;
25
26
    /** @var App */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
27
    protected $app;
28
29
    public function __construct(Lang $lang, App $app)
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
30
    {
31
        $this->lang = $lang;
32
        $this->app  = $app;
33
    }
34
35
    /**
36
     * 路由初始化(路由规则注册)
37
     * @access public
38
     * @param Request $request
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
39
     * @param Closure $next
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
40
     * @return void
41
     */
42
    public function handle($request, Closure $next)
43
    {
44
        // 读取默认语言
45
        $this->lang->range($this->app->config->get('app.default_lang', 'zh-cn'));
0 ignored issues
show
Bug introduced by
It seems like $this->app->config->get(...default_lang', 'zh-cn') can also be of type array and array; however, parameter $range of think\Lang::range() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

45
        $this->lang->range(/** @scrutinizer ignore-type */ $this->app->config->get('app.default_lang', 'zh-cn'));
Loading history...
46
47
        if ($this->app->config->get('app.lang_switch_on', false)) {
48
            // 开启多语言机制 检测当前语言
49
            $this->lang->detect();
50
        }
51
52
        $request->setLangset($this->lang->range());
53
54
        // 加载系统语言包
55
        $this->lang->load([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
56
            $this->app->getThinkPath() . 'lang' . DIRECTORY_SEPARATOR . $request->langset() . '.php',
57
            $this->app->getAppPath() . 'lang' . DIRECTORY_SEPARATOR . $request->langset() . '.php',
58
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
59
60
        return $next($request);
61
    }
62
}
63