Test Failed
Push — master ( 37d3cb...34a83f )
by kill
03:43
created

App   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 41
rs 10
c 1
b 0
f 0
ccs 0
cts 7
cp 0
wmc 5
lcom 2
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A initEnv() 0 17 3
A initContainer() 0 5 1
1
<?php
2
/**
3
 * Created by rozbo at 2017/3/18 下午8:52
4
 */
5
6
namespace puck;
7
8
9
use Dotenv\Dotenv;
10
use Whoops\Run;
11
12
class App extends Container {
13
14
    /**
15
     * 应用的根目录.
16
     *
17
     * @var string
18
     */
19
    protected $basePath;
20
    public function __construct($basePath) {
21
        $this->basePath=$basePath;
22
        $this->initEnv();
23
        $this->initContainer();
24
    }
25
26
    private function initEnv(){
27
        $dotEnv = new Dotenv($this->basePath);
28
        $dotEnv->load();
29
        date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai'));
30
        define('IS_CLI', php_sapi_name() == 'cli');
31
        if (env('DEBUG',false)) {
32
            error_reporting(E_ALL);
33
            @ini_set('display_errors', 'On');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
34
            //@ob_start();
35
            $whoops=new Run;
36
            $handle=IS_CLI ? "PlainTextHandler" : "PrettyPageHandler";
37
            $handle="\\Whoops\\Handler\\".$handle;
38
            $whoops->pushHandler(new $handle);
39
            $whoops->register();
40
        }
41
42
    }
43
    /**
44
     * 初始化容器
45
     */
46
    private function initContainer() {
47
        static::setInstance($this);
48
        $this->instance('app',$this);
49
        $this->bind('pinyin','\puck\helpers\PinYin');
50
    }
51
52
}