Passed
Pull Request — main (#122)
by Andreas
02:10
created

CrateStatement::fetchAll()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
5
 * license agreements.  See the NOTICE file distributed with this work for
6
 * additional information regarding copyright ownership.  Crate licenses
7
 * this file to you under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.  You may
9
 * obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
16
 * License for the specific language governing permissions and limitations
17
 * under the License.
18
 *
19
 * However, if you have executed another commercial license agreement
20
 * with Crate these terms will supersede the license and you may use the
21
 * software solely pursuant to the terms of the relevant commercial agreement.
22
 */
23
24
namespace Crate\DBAL\Driver\PDOCrate;
25
26
use Crate\PDO\PDOInterface;
27
use Crate\PDO\PDOStatement;
28
use Doctrine\DBAL\Driver\PDO\Exception;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Crate\DBAL\Driver\PDOCrate\Exception. Consider defining an alias.

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...
29
use Doctrine\DBAL\Driver\PDOStatementImplementations;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Driver\PDOStatementImplementations was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Doctrine\DBAL\Driver\Result as ResultInterface;
31
use Doctrine\DBAL\Driver\Statement as StatementInterface;
32
use Doctrine\DBAL\ParameterType;
33
use Doctrine\Deprecations\Deprecation;
34
use PDO;
35
36
/**
37
 * @internal
38
 */
39
final class CrateStatement implements StatementInterface
40
{
41
    private PDOInterface $pdo;
42
    private PDOStatement $stmt;
43
44
    /**
45
     * @param string              $sql
46
     * @param array<string,mixed> $options
47
     */
48 110
    public function __construct(PDOInterface $pdo, $sql, $options = [])
49
    {
50 110
        $this->pdo  = $pdo;
51 110
        $this->stmt = $pdo->prepare($sql, $options);
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57 108
    public function execute($params = null): ResultInterface
58
    {
59
60 108
        if ($params !== null) {
61 6
            Deprecation::trigger(
62 6
                'doctrine/dbal',
63 6
                'https://github.com/doctrine/dbal/pull/5556',
64 6
                'Passing $params to Statement::execute() is deprecated. Bind parameters using'
65 6
                . ' Statement::bindParam() or Statement::bindValue() instead.',
66 6
            );
67
        }
68 108
        $this->stmt->execute($params);
69 108
        return new Result($this);
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75
    public function columnCount(): int
76
    {
77
        return $this->stmt->columnCount();
78
    }
79
80
    /**
81
     * {@inheritDoc}
82
     */
83 90
    public function rowCount(): int
84
    {
85 90
        return $this->stmt->rowCount();
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91 86
    public function bindValue($param, $value, $type = ParameterType::STRING)
92
    {
93 86
        return $this->stmt->bindValue($param, $value, $type);
94
    }
95
96
    /**
97
     * {@inheritDoc}
98
     */
99 12
    public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
100
    {
101 12
        return $this->stmt->bindParam($param, $variable, $type, $length);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->stmt->bindParam($...riable, $type, $length) targeting Crate\PDO\PDOStatement::bindParam() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
102
    }
103
104
    /**
105
     * {@inheritDoc}
106
     */
107 72
    public function fetch(
108
        $fetch_style = PDO::FETCH_ASSOC,
109
        $cursor_orientation = PDO::FETCH_ORI_NEXT,
110
        $cursor_offset = 0,
111
    ) {
112 72
        return $this->stmt->fetch($fetch_style, $cursor_orientation, $cursor_offset);
113
    }
114
115
    /**
116
     * @phpstan-param PDO::FETCH_* $mode
117
     *
118
     * @return list<mixed>
0 ignored issues
show
Bug introduced by
The type Crate\DBAL\Driver\PDOCrate\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
119
     *
120
     * @throws Exception
121
     */
122
    public function fetchAll(int $mode): array
123
    {
124
        return $this->stmt->fetchAll($mode);
0 ignored issues
show
Deprecated Code introduced by
The function Crate\PDO\PDOStatement::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

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

124
        return /** @scrutinizer ignore-deprecated */ $this->stmt->fetchAll($mode);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug Best Practice introduced by
The expression return $this->stmt->fetchAll($mode) returns the type array<mixed,mixed> which is incompatible with the documented return type Crate\DBAL\Driver\PDOCrate\list.
Loading history...
125
    }
126
127 8
    public function fetchColumn($column_number = 0)
128
    {
129 8
        return $this->stmt->fetchColumn($column_number);
130
    }
131
132
    /**
133
     * {@inheritDoc}
134
     */
135
    public function closeCursor(): bool
136
    {
137
        return $this->stmt->closeCursor();
138
    }
139
140
    /**
141
     * Gets the wrapped CrateDB PDOStatement.
142
     *
143
     * @return PDOStatement
144
     */
145 2
    public function getWrappedStatement(): PDOStatement
146
    {
147 2
        return $this->stmt;
148
    }
149
}
150