Completed
Push — master ( 7c9586...c8ce39 )
by Oscar
01:44
created

Update   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 51.43 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 18
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 18 18 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
declare(strict_types = 1);
3
4
namespace SimpleCrud\Query;
5
6
use SimpleCrud\Events\CreateUpdateQuery;
7
use SimpleCrud\Table;
8
9
final class Update implements QueryInterface
10
{
11
    use Traits\Common;
12
    use Traits\HasRelatedWith;
13
14
    private $allowedMethods = [
15
        'set',
16
        'setFlag',
17
        'where',
18
        'orWhere',
19
        'catWhere',
20
        'orderBy',
21
        'limit',
22
        'offset',
23
    ];
24
25 View Code Duplication
    public function __construct(Table $table, array $data = [])
26
    {
27
        $this->table = $table;
28
29
        $this->query = $table->getDatabase()
30
            ->update()
31
            ->table((string) $table);
32
33
        foreach ($data as $fieldName => $value) {
34
            $this->table->{$fieldName}->update($this->query, $value);
35
        }
36
37
        $eventDispatcher = $table->getEventDispatcher();
38
39
        if ($eventDispatcher) {
40
            $eventDispatcher->dispatch(new CreateUpdateQuery($this));
0 ignored issues
show
Documentation introduced by
new \SimpleCrud\Events\CreateUpdateQuery($this) is of type object<SimpleCrud\Events\CreateUpdateQuery>, but the function expects a object<Psr\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
        }
42
    }
43
}
44