Completed
Push — master ( 3efc16...d615e7 )
by Woody
12s
created

UpdateQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 29
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B sql() 22 22 4

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 Latitude\QueryBuilder\MySQL;
5
6
use Latitude\QueryBuilder\Identifier;
0 ignored issues
show
Bug introduced by Peter Gnodde
This use statement conflicts with another class in this namespace, Latitude\QueryBuilder\MySQL\Identifier.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use Latitude\QueryBuilder\Traits\CanConvertIteratorToString;
8
use Latitude\QueryBuilder\Traits\CanLimit;
9
use Latitude\QueryBuilder\Traits\CanOrderBy;
10
use Latitude\QueryBuilder\UpdateQuery as Query;
11
12 View Code Duplication
class UpdateQuery extends Query
0 ignored issues
show
Duplication introduced by Peter Gnodde
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    use CanConvertIteratorToString;
15
    use CanLimit;
16
    use CanOrderBy;
17
18 4
    public function sql(Identifier $identifier = null): string
19
    {
20 4
        $identifier = $this->getDefaultIdentifier($identifier);
21
22 4
        $parts = [];
23
24 4
        if ($this->orderBy) {
0 ignored issues
show
Bug Best Practice introduced by Peter Gnodde
The expression $this->orderBy of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
25 2
            $parts[] = $this->orderByAsSql($identifier);
26
        }
27
28 4
        if (isset($this->limit)) {
29 1
            $parts[] = $this->limitAsSql();
30
        }
31
32 4
        $sql = parent::sql($identifier);
33
34 4
        if (!$parts) {
0 ignored issues
show
Bug Best Practice introduced by Peter Gnodde
The expression $parts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
35 1
            return $sql;
36
        }
37
38 3
        return sprintf('%s %s', $sql, implode(' ', $parts));
39
    }
40
}
41