Passed
Push — master ( 0d676e...35e015 )
by Wilmer
04:03
created

src/Connection.php (7 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite;
6
7
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
0 ignored issues
show
The type Yiisoft\Db\Driver\Pdo\AbstractPdoConnection 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...
8
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
0 ignored issues
show
The type Yiisoft\Db\Driver\Pdo\PdoCommandInterface 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...
9
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
10
use Yiisoft\Db\Schema\Quoter;
11
use Yiisoft\Db\Schema\QuoterInterface;
12
use Yiisoft\Db\Schema\SchemaInterface;
13
use Yiisoft\Db\Transaction\TransactionInterface;
14
15
use function str_starts_with;
16
17
/**
18
 * Implements a connection to a database via PDO (PHP Data Objects) for SQLite Server.
19
 *
20
 * @link https://www.php.net/manual/en/ref.pdo-sqlite.php
21
 */
22
final class Connection extends AbstractPdoConnection
23
{
24
    /**
25
     * Reset the connection after cloning.
26
     */
27 1
    public function __clone()
28
    {
29 1
        $this->transaction = null;
0 ignored issues
show
Bug Best Practice introduced by
The property transaction does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31 1
        if (!str_starts_with($this->driver->getDsn(), 'sqlite::memory:')) {
32
            /** Reset PDO connection, unless its sqlite in-memory, which can only have one connection. */
33 1
            $this->pdo = null;
0 ignored issues
show
Bug Best Practice introduced by
The property pdo does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
        }
35
    }
36
37 286
    public function createCommand(string $sql = null, array $params = []): PdoCommandInterface
38
    {
39 286
        $command = new Command($this);
40
41 286
        if ($sql !== null) {
42 249
            $command->setSql($sql);
43
        }
44
45 286
        if ($this->logger !== null) {
46 3
            $command->setLogger($this->logger);
47
        }
48
49 286
        if ($this->profiler !== null) {
50 4
            $command->setProfiler($this->profiler);
51
        }
52
53 286
        return $command->bindValues($params);
54
    }
55
56 15
    public function createTransaction(): TransactionInterface
57
    {
58 15
        return new Transaction($this);
59
    }
60
61 508
    public function getQueryBuilder(): QueryBuilderInterface
62
    {
63 508
        if ($this->queryBuilder === null) {
64 508
            $this->queryBuilder = new QueryBuilder(
0 ignored issues
show
Bug Best Practice introduced by
The property queryBuilder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
65 508
                $this->getQuoter(),
66 508
                $this->getSchema(),
67 508
            );
68
        }
69
70 508
        return $this->queryBuilder;
71
    }
72
73 538
    public function getQuoter(): QuoterInterface
74
    {
75 538
        if ($this->quoter === null) {
76 538
            $this->quoter = new Quoter('`', '`', $this->getTablePrefix());
0 ignored issues
show
Bug Best Practice introduced by
The property quoter does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
77
        }
78
79 538
        return $this->quoter;
80
    }
81
82 536
    public function getSchema(): SchemaInterface
83
    {
84 536
        if ($this->schema === null) {
85 536
            $this->schema = new Schema($this, $this->schemaCache);
0 ignored issues
show
Bug Best Practice introduced by
The property schema does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
86
        }
87
88 536
        return $this->schema;
89
    }
90
}
91