Completed
Push — 6.0 ( 7c4b73...f9b4e1 )
by liu
04:19
created

ModelService::boot()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 6
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 6
b 0
f 0
nc 1
nop 0
dl 0
loc 19
ccs 0
cts 10
cp 0
crap 12
rs 9.9332
1
<?php
2
// +----------------------------------------------------------------------
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: yunwuxin <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\service;
14
15
use think\Model;
16
use think\Service;
17
18
/**
19
 * 模型服务类
20
 */
21
class ModelService extends Service
22
{
23
    public function boot()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function boot()
Loading history...
24
    {
25
        Model::maker(function (Model $model) {
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...
26
            $db     = $this->app->db;
27
            $config = $this->app->config;
28
            $model->setDb($db);
29
30
            $isAutoWriteTimestamp = $model->getAutoWriteTimestamp();
31
32
            if (is_null($isAutoWriteTimestamp)) {
0 ignored issues
show
introduced by
The condition is_null($isAutoWriteTimestamp) is always false.
Loading history...
33
                // 自动写入时间戳
34
                $model->isAutoWriteTimestamp($config->get('database.auto_timestamp', 'timestamp'));
35
            }
36
37
            $dateFormat = $model->getDateFormat();
38
39
            if (is_null($dateFormat)) {
0 ignored issues
show
introduced by
The condition is_null($dateFormat) is always false.
Loading history...
40
                // 设置时间戳格式
41
                $model->setDateFormat($config->get('database.datetime_format', 'Y-m-d H:i:s'));
42
            }
43
44
        });
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...
45
    }
46
}
47