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

App::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
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
}