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

ExtendedPDO::queryWithParam()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 10
cp 0
rs 9.2
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 2
crap 12
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