GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 083d1a...28e483 )
by cao
03:15
created

functions.php ➔ models()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
ccs 2
cts 3
cp 0.6667
crap 2.1481
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace PhpBoot;
3
use PhpBoot\DB\DB;
4
use PhpBoot\ORM\ModelWithClass;
5
use PhpBoot\ORM\ModelWithObject;
6
use PhpBoot\Utils\Logger;
7
8
if (! function_exists('PhpBoot\abort')) {
9
    /**
10
     * 抛出异常, 并记录日志
11
     * @param string|\Exception $error
12
     * @param array $context
13
     * @param string $level "error"|"warning"|"info"|"debug"|null
14
     * @throws \Exception
15
     */
16
    function abort($error = '', $context=[], $level='warning')
17
    {
18 9
        if(is_object($context)){
19
            $context = get_object_vars($context);
20
        }
21 9
        if($error instanceof \Exception){
22 8
            $e = $error;
23 8
            $message = "exception '".get_class($error)."' with message {$error->getMessage()}";
24 8
        }else{
25 1
            $e = new \RuntimeException($error);
26 1
            $message = $error;
27
        }
28 9
        $trace = $e->getTrace();
29
30 9
        if($e->getFile() == __FILE__){
31 1
            $file = $trace[0]['file'];
32 1
            $line = $trace[0]['line'];
33 1
        }else{
34 8
            $file = $e->getFile();
35 8
            $line = $e->getLine();
36
        }
37 9
        if($level){
38 9
           Logger::$level($message, $context +['@file'=>$file, '@line'=>$line]);
39 9
        }
40 9
        throw $e;
41
    }
42
43
}
44
45
if (!function_exists('PhpBoot\model')) {
46
47
    /**
48
     * @param DB $db
49
     * @param @param object
50
     * @return ModelWithObject
51
     */
52
    function model(DB $db, $entity)
53
    {
54 4
        return $db->getApp()->make(ModelWithObject::class, ['db'=>$db, 'entity'=>$entity]);
55
    }
56
57
    /**
58
     * @param DB $db
59
     * @param @param string $entity
60
     * @return ModelWithClass
61
     */
62
    function models(DB $db, $entity)
63
    {
64 6
        if(is_object($entity)){
65
            return $db->getApp()->make(ModelWithObject::class, ['db'=>$db, 'entity'=>$entity]);
66
        }else{
67 6
            return $db->getApp()->make(ModelWithClass::class, ['db'=>$db, 'entityName'=>$entity]);
68
        }
69
    }
70
}