Failed Conditions
Pull Request — master (#6959)
by Matthew
19:32
created

SingleTableDeleteUpdateExecutor::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query\Exec;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\ORM\Query\AST;
9
10
/**
11
 * Executor that executes the SQL statements for DQL DELETE/UPDATE statements on classes
12
 * that are mapped to a single table.
13
 */
14
class SingleTableDeleteUpdateExecutor extends AbstractSqlExecutor
15
{
16
    /**
17
     * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
18
     */
19
    public function __construct(AST\Node $AST, $sqlWalker)
20
    {
21
        if ($AST instanceof AST\UpdateStatement) {
22
            $this->sqlStatements = $sqlWalker->walkUpdateStatement($AST);
0 ignored issues
show
Documentation Bug introduced by
It seems like $sqlWalker->walkUpdateStatement($AST) of type string is incompatible with the declared type string[] of property $sqlStatements.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
        } elseif ($AST instanceof AST\DeleteStatement) {
24
            $this->sqlStatements = $sqlWalker->walkDeleteStatement($AST);
25
        }
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function execute(Connection $conn, array $params, array $types)
32
    {
33
        return $conn->executeUpdate($this->sqlStatements, $params, $types);
0 ignored issues
show
Bug introduced by
$this->sqlStatements of type string[] is incompatible with the type string expected by parameter $query of Doctrine\DBAL\Connection::executeUpdate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        return $conn->executeUpdate(/** @scrutinizer ignore-type */ $this->sqlStatements, $params, $types);
Loading history...
Bug Best Practice introduced by
The expression return $conn->executeUpd...ments, $params, $types) returns the type integer which is incompatible with the return type mandated by Doctrine\ORM\Query\Exec\...tSqlExecutor::execute() of Doctrine\DBAL\Driver\Statement.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
34
    }
35
}
36