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.
Completed
Push — master ( b8e87e...d83110 )
by cao
13:02 queued 09:59
created

ModelWithClass::withTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PhpBoot\ORM;
3
4
use Doctrine\Common\Cache\Cache;
5
use PhpBoot\DB\DB;
6
7
class ModelWithClass
8
{
9
    /**
10
     * Model constructor.
11
     * @param DB $db
12
     * @param string $entityName
13
     * @param Cache $cache
14
     */
15 7
    public function __construct(DB $db, $entityName, Cache $cache)
0 ignored issues
show
Unused Code introduced by
The parameter $cache is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
    {
17 7
        $this->db = $db;
18 7
        $builder = $db->getApp()->get(ModelContainerBuilder::class);
19 7
        $this->entity = $builder->build($entityName);
20 7
    }
21
22
    /**
23
     * @param string $id
24
     * @return mixed|null
25
     */
26 1
    public function find($id)
27
    {
28 1
        $row = $this->db->select($this->getColumns())
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $row is correct as $this->db->select($this-... = ?", $id)->getFirst() (which targets PhpBoot\DB\rules\select\GetRule::getFirst()) 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...
29 1
            ->from($this->entity->getTable())
30 1
            ->where("`{$this->entity->getPK()}` = ?", $id)
31 1
            ->getFirst();
32 1
        if($row){
33
            return $this->entity->make($row, false);
34
        }else{
35 1
            return null;
36
        }
37
    }
38
39
    /**
40
     * @return int rows deleted
41
     */
42 1
    public function delete($id)
43
    {
44 1
        return $this->db->deleteFrom($this->entity->getTable())
45 1
            ->where([$this->entity->getPK()=>$id])
46 1
            ->limit(1)
47 1
            ->exec()->rows;
48
    }
49
50
    /**
51
     * where 语法见 @see WhereRule
52
     * @param array|string $expr
0 ignored issues
show
Bug introduced by
There is no parameter named $expr. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
53
     * @param mixed|null $_
54
     * @return \PhpBoot\DB\rules\basic\WhereRule
55
     */
56 1
    public function deleteWhere($conditions, $_=null)
0 ignored issues
show
Unused Code introduced by
The parameter $conditions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $_ is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58 1
        $query = $this->db->deleteFrom($this->entity->getTable());
59 1
        return call_user_func_array([$query, 'where'], func_get_args());
60
    }
61
62
    /**
63
     * @return false|int
64
     */
65
    public function count()
66
    {
67
        return $this->db->select($this->getColumns())
68
            ->from($this->entity->getTable())
69
            ->count();
70
    }
71
72
    /**
73
     * where 语法见 @see WhereRule
74
     * @param array|string|callable|null $conditions
75
     * @param string $_
76
     * @return \PhpBoot\DB\rules\select\WhereRule
77
     */
78 2
    public function findWhere($conditions=null, $_=null)
0 ignored issues
show
Unused Code introduced by
The parameter $conditions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $_ is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80 2
        $query =  $this->db->select($this->getColumns())
81 2
            ->from($this->entity->getTable());
82
        $query->context->resultHandler = function ($result){
83
            foreach ($result as &$i){
84
                $i = $this->entity->make($i, false);
85
            }
86
            return $result;
87
        };
88 2
        return call_user_func_array([$query, 'where'], func_get_args());
89
    }
90
91
    /**
92
     * @param int|string $id
93
     * @param array $values
94
     * @return int updated row count
95
     */
96 1
    public function update($id, $values)
97
    {
98 1
        return $this->db->update($this->entity->getTable())
99 1
            ->set($values)
100 1
            ->where([$this->entity->getPK()=>$id])
101 1
            ->exec();
102
    }
103
104
    /**
105
     * @param array $values
106
     * @param array|string|callable $conditions  where 语法见 @see WhereRule
107
     * @param string $_
108
     * @return \PhpBoot\DB\rules\basic\WhereRule
109
     */
110 1
    public function updateWhere($values, $conditions, $_=null)
0 ignored issues
show
Unused Code introduced by
The parameter $conditions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $_ is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    {
112 1
        $query =  $this->db->update($this->entity->getTable())->set($values);
113 1
        return call_user_func_array([$query, 'where'], array_slice(func_get_args(),1));
114
    }
115
116 3
    /**
117
     * set entity table name
118 3
     * @param string $tableName
119 3
     * @return $this
120 3
     */
121 3
    public function withTable($tableName)
122 3
    {
123
        $this->entity->setTable($tableName);
124
        return $this;
125
    }
126
127
    protected function getColumns()
128
    {
129
        $columns = [];
130
        foreach ($this->entity->getProperties() as $p){
131
            $columns[] = $p->name;
132
        }
133
        return $columns;
134
    }
135
    /**
136
     * @var ModelContainer
137
     */
138
    protected $entity;
139
    /**
140
     * @var DB
141
     */
142
    protected $db;
143
}