Completed
Push — master ( dbcbc1...04d817 )
by Sébastien
02:01
created

PdoMysqlAdapter::getConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Soluble\DbWrapper\Adapter;
4
5
use Soluble\DbWrapper\Exception;
6
use Soluble\DbWrapper\Adapter\Pdo\GenericPdo;
7
use Soluble\DbWrapper\Connection\MysqlConnection;
8
use PDO;
9
10
class PdoMysqlAdapter extends GenericPdo implements AdapterInterface
11
{
12
13
    /**
14
     *
15
     * @var \PDO
16
     */
17
    protected $resource;
18
19
20
    /**
21
     * Constructor
22
     *
23
     * @throws Exception\InvalidArgumentException
24
     * @throws Exception\RuntimeException
25
     * @param \PDO $resource
26
     * @param \PDO $connection
0 ignored issues
show
Bug introduced by
There is no parameter named $connection. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
27
     */
28 7
    public function __construct(PDO $resource)
29
    {
30 7
        $this->checkEnvironment();
31 7
        if ($resource->getAttribute(\PDO::ATTR_DRIVER_NAME) != 'mysql') {
32 1
            $msg = __CLASS__ . " requires pdo connection to be 'mysql'";
33 1
            throw new Exception\InvalidArgumentException($msg);
34
        }
35 7
        $this->resource = $resource;
36 7
        $this->connection = new MysqlConnection($this, $resource);
0 ignored issues
show
Bug introduced by
The property connection does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37 7
    }
38
    
39
    /**
40
     * {@inheritdoc}
41
     * @return MysqlConnection
42
     */
43 2
    public function getConnection() 
44
    {
45 2
        return $this->connection;
46
    }
47
    
48
}
49