Completed
Push — master ( 00d511...a1b2ba )
by Sebastian
02:16
created

ExtendedPDO   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 34
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A queryWithParam() 0 22 3
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2017, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Storage;
13
14
use \PDO;
15
use \PDOStatement;
16
17
/**
18
 * Extended PDO
19
 */
20
class ExtendedPDO extends PDO
21
{
22
    /**
23
     * Executes an SQL statement with parameters, 
24
     * returning a result set as a PDOStatement object
25
     * 
26
     * @param string $query SQL statement
27
     * @param array $param Parameter as array as 
28
     * 
29
     * @return PDOStatement
30
     */
31
    public function queryWithParam(string $query, array $param) : \PDOStatement
32
    {
33
        $statment = parent::prepare($query);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (prepare() instead of queryWithParam()). Are you sure this is correct? If so, you might want to change this to $this->prepare().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
34
               
35
        foreach ($param as $value) {
36
            
37
            if (strpos($value[0], ':') !== 0){
38
                throw new InvalidArgumentException(__METHOD__.': Parameter name will be in the form :name');
39
            }
40
            
41
            //reassign as reference
42
            //because bindParam need it as reference
43
            $ref = $value;
44
            $ref[1] = &$value[1];
45
46
            call_user_func_array([$statment, "bindParam"], $ref);
47
        }
48
        
49
        $statment->execute();
50
51
        return $statment;
52
    }
53
}
54
55