Passed
Push — 6.0 ( 3dc798...7ca19f )
by liu
02:48
created

Jump::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
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
12
namespace think\response;
13
14
use think\Response;
15
use think\View;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, think\response\View. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
17
class Jump extends Response
1 ignored issue
show
Coding Style introduced by
Missing doc comment for class Jump
Loading history...
18
{
19
    protected $contentType = 'text/html';
20
21
    protected $view;
22
23
    public function __construct(View $view, $data = '', int $code = 200)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
24
    {
25
        parent::__construct($data, $code);
26
        $this->view = $view;
27
    }
28
29
    /**
30
     * 处理数据
31
     * @access protected
32
     * @param  mixed $data 要处理的数据
33
     * @return string
34
     * @throws \Exception
35
     */
36
    protected function output($data): string
37
    {
38
        return $this->view->assign($data)
39
            ->fetch($this->options['jump_template']);
40
    }
41
}
42