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

DeleteQuery::sql()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 22
Code Lines 11

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 22
loc 22
ccs 11
cts 11
cp 1
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 11
nc 8
nop 1
crap 4
1
<?php
2
namespace Latitude\QueryBuilder\MySQL;
3
4
use Latitude\QueryBuilder\DeleteQuery as Query;
5
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...
6
use Latitude\QueryBuilder\Traits\CanConvertIteratorToString;
7
use Latitude\QueryBuilder\Traits\CanLimit;
8
use Latitude\QueryBuilder\Traits\CanOrderBy;
9
10 View Code Duplication
class DeleteQuery 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...
11
{
12
    use CanConvertIteratorToString;
13
    use CanLimit;
14
    use CanOrderBy;
15
16 4
    public function sql(Identifier $identifier = null): string
17
    {
18 4
        $identifier = $this->getDefaultIdentifier($identifier);
19
20 4
        $parts = [];
21
22 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...
23 2
            $parts[] = $this->orderByAsSql($identifier);
24
        }
25
26 4
        if (isset($this->limit)) {
27 1
            $parts[] = $this->limitAsSql();
28
        }
29
30 4
        $sql = parent::sql($identifier);
31
32 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...
33 1
            return $sql;
34
        }
35
36 3
        return sprintf('%s %s', $sql, implode(' ', $parts));
37
    }
38
}