Completed
Push — 6.0 ( a99d0b...cc2e0b )
by liu
02:48
created

ModelService::boot()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 1
nop 0
dl 0
loc 25
ccs 0
cts 12
cp 0
crap 30
rs 9.5555
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: 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
class ModelService extends Service
1 ignored issue
show
Coding Style introduced by
Missing doc comment for class ModelService
Loading history...
19
{
20
    public function boot()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function boot()
Loading history...
21
    {
22
        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...
23
            $db = $this->app->db;
24
            $model->setDb($db);
25
26
            $isAutoWriteTimestamp = $model->getAutoWriteTimestamp();
27
28
            if (is_null($isAutoWriteTimestamp)) {
0 ignored issues
show
introduced by
The condition is_null($isAutoWriteTimestamp) is always false.
Loading history...
29
                // 自动写入时间戳
30
                $model->isAutoWriteTimestamp($db->getConfig('auto_timestamp'));
31
            }
32
33
            $dateFormat = $model->getDateFormat();
34
35
            if (is_null($dateFormat)) {
0 ignored issues
show
introduced by
The condition is_null($dateFormat) is always false.
Loading history...
36
                // 设置时间戳格式
37
                $model->setDateFormat($db->getConfig('datetime_format'));
38
            }
39
40
            $connection = $model->getConnection();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $connection is correct as $model->getConnection() targeting think\Model::getConnection() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
42
            if (!empty($connection) && is_array($connection)) {
0 ignored issues
show
introduced by
The condition is_array($connection) is always false.
Loading history...
43
                // 设置模型的数据库连接
44
                $model->setConnection(array_merge($db->getConfig(), $connection));
45
            }
46
47
        });
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...
48
    }
49
}
50