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

PDOConnection::exec()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 10
cc 2
nc 3
nop 1
crap 6
1
<?php
2
/**
3
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
4
 * license agreements.  See the NOTICE file distributed with this work for
5
 * additional information regarding copyright ownership.  Crate licenses
6
 * this file to you under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.  You may
8
 * obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15
 * License for the specific language governing permissions and limitations
16
 * under the License.
17
 *
18
 * However, if you have executed another commercial license agreement
19
 * with Crate these terms will supersede the license and you may use the
20
 * software solely pursuant to the terms of the relevant commercial agreement.
21
 */
22
23
namespace Crate\DBAL\Driver\PDOCrate;
24
25
use Crate\PDO\PDO;
26
use Doctrine\DBAL\Driver\PDO\Exception;
27
use Doctrine\DBAL\Driver\PDO\Statement;
28
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
29
use Doctrine\DBAL\Driver\Statement as StatementInterface;
30
31
class PDOConnection extends PDO implements ServerInfoAwareConnection
0 ignored issues
show
Deprecated Code introduced by
The interface Doctrine\DBAL\Driver\ServerInfoAwareConnection has been deprecated: The methods defined in this interface will be made part of the {@see Driver} interface in the next major release. ( Ignorable by Annotation )

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

31
class PDOConnection extends PDO implements /** @scrutinizer ignore-deprecated */ ServerInfoAwareConnection

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

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

Loading history...
Deprecated Code introduced by
The class Crate\PDO\PDO has been deprecated: The API interface `Crate\PDO\PDO` is deprecated and will be removed on one of the upcoming releases. Please use `Crate\PDO\PDOCrateDB` instead. ( Ignorable by Annotation )

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

31
class PDOConnection extends /** @scrutinizer ignore-deprecated */ PDO implements ServerInfoAwareConnection
Loading history...
32
{
33
    /**
34
     * @param string $dsn
35
     * @param string $user
36 12
     * @param string $password
37
     * @param array $options
38 12
     */
39 12
    public function __construct($dsn, $user = null, $password = null, array $options = null)
40 12
    {
41
        parent::__construct($dsn, $user, $password, $options);
42
        $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, CrateStatement::class);
43
        $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
44
    }
45
46
    /**
47
     * Checks whether a query is required to retrieve the database server version.
48 6
     *
49
     * @return boolean True if a query is required to retrieve the database server version, false otherwise.
50 6
     */
51
    public function requiresQueryForServerVersion()
52
    {
53
        return false;
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     *
59
     * References:
60
     * - https://github.com/doctrine/dbal/issues/2025
61
     * - https://github.com/doctrine/dbal/pull/517
62
     * - https://github.com/doctrine/dbal/pull/373
63
     */
64
    public function prepare($sql, $options = null): StatementInterface
65
    {
66
        try {
67
            $stmt = $this->connection->prepare($sql, $options);
0 ignored issues
show
Bug Best Practice introduced by
The property connection does not exist on Crate\DBAL\Driver\PDOCrate\PDOConnection. Did you maybe forget to declare it?
Loading history...
68
            assert($stmt instanceof PDOStatement);
0 ignored issues
show
Bug introduced by
The type Crate\DBAL\Driver\PDOCrate\PDOStatement was not found. Did you mean PDOStatement? If so, make sure to prefix the type with \.
Loading history...
69
70
            return new Statement($stmt);
71
        } catch (PDOException $exception) {
0 ignored issues
show
Bug introduced by
The type Crate\DBAL\Driver\PDOCrate\PDOException was not found. Did you mean PDOException? If so, make sure to prefix the type with \.
Loading history...
72
            throw Exception::new($exception);
73
        }
74
    }
75
76
    /**
77
     * {@inheritDoc}
78
     */
79
    public function exec($sql): int
80
    {
81
        try {
82
            $result = $this->connection->exec($sql);
0 ignored issues
show
Bug Best Practice introduced by
The property connection does not exist on Crate\DBAL\Driver\PDOCrate\PDOConnection. Did you maybe forget to declare it?
Loading history...
83
84
            assert($result !== false);
85
86
            return $result;
87
        } catch (PDOException $exception) {
88
            throw Exception::new($exception);
89
        }
90
    }
91
}
92