Test Failed
Pull Request — master (#175)
by Def
29:08 queued 25:21
created

CommandPDO::insertEx()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use PDOException;
8
use Throwable;
9
use Yiisoft\Db\Driver\PDO\AbstractCommandPDO;
10
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
11
use Yiisoft\Db\Exception\ConvertException;
12
use Yiisoft\Db\Exception\Exception;
13
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
14
15
use function is_array;
16
17
final class CommandPDO extends AbstractCommandPDO
18
{
19
    /**
20
     * @inheritDoc
21
    */
22 6
    public function insertWithReturningPks(string $table, array $columns): bool|array
23
    {
24 6
        $params = [];
25
26 6
        $sql = $this->queryBuilder()->insertWithReturningPks($table, $columns, $params);
0 ignored issues
show
Bug introduced by
The method insertWithReturningPks() does not exist on Yiisoft\Db\QueryBuilder\QueryBuilderInterface. Did you maybe mean insert()? ( Ignorable by Annotation )

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

26
        $sql = $this->queryBuilder()->/** @scrutinizer ignore-call */ insertWithReturningPks($table, $columns, $params);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
28 6
        $this->setSql($sql)->bindValues($params);
29 6
        $this->prepare(false);
30
31
        /** @psalm-var array|bool $result */
32 6
        $result = $this->queryOne();
33
34 6
        return is_array($result) ? $result : false;
35
    }
36
37 280
    public function queryBuilder(): QueryBuilderInterface
38
    {
39 280
        return $this->db->getQueryBuilder();
40
    }
41
42
    /**
43
     * @psalm-suppress UnusedClosureParam
44
     *
45
     * @throws Exception
46
     * @throws Throwable
47
     */
48 257
    protected function internalExecute(string|null $rawSql): void
49
    {
50 257
        $attempt = 0;
51
52 257
        while (true) {
53
            try {
54
                if (
55 257
                    ++$attempt === 1
56 257
                    && $this->isolationLevel !== null
57 257
                    && $this->db->getTransaction() === null
58
                ) {
59 1
                    $this->db->transaction(
60 1
                        fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql),
0 ignored issues
show
Unused Code introduced by
The parameter $db is not used and could be removed. ( Ignorable by Annotation )

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

60
                        fn (/** @scrutinizer ignore-unused */ ConnectionPDOInterface $db) => $this->internalExecute($rawSql),

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

Loading history...
61 1
                        $this->isolationLevel
62 1
                    );
63
                } else {
64 257
                    $this->pdoStatement?->execute();
65
                }
66 256
                break;
67 7
            } catch (PDOException $e) {
68 7
                $rawSql = $rawSql ?: $this->getRawSql();
69 7
                $e = (new ConvertException($e, $rawSql))->run();
70
71 7
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
72 7
                    throw $e;
73
                }
74
            }
75
        }
76
    }
77
}
78