Completed
Push — master ( 1857e6...d96bec )
by Joao
03:02
created

src/Database/SQLBind.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace ByJG\AnyDataset\Database;
4
5
use ByJG\AnyDataset\ConnectionManagement;
6
7
/**
8
 * Class to create and manipulate Several Data Types
9
 *
10
 */
11
class SQLBind
12
{
13
14
    /**
15
     * Each provider have your own model for pass parameter. This method define how each provider name define the parameters
16
     *
17
     * @param ConnectionManagement $connData
18
     * @return string
19
     */
20
    public static function getParamModel(ConnectionManagement $connData)
21
    {
22
        if ($connData->getExtraParam("parammodel") != "") {
23
            return $connData->getExtraParam("parammodel");
24
        } elseif ($connData->getDriver() == "sqlrelay") {
25
            return "?";
26
        } else {
27
            return ":_";
28
        }
29
    }
30
31
    /**
32
     * Transform generic parameters [[PARAM]] in a parameter recognized by the provider name based on current DbParameter array.
33
     *
34
     * @param ConnectionManagement $connData
35
     * @param string $sql
36
     * @param array $param
0 ignored issues
show
There is no parameter named $param. Did you maybe mean $params?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

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

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

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

Loading history...
37
     * @return array An array with the adjusted SQL and PARAMs
38
     */
39
    public static function parseSQL(ConnectionManagement $connData, $sql, $params = null)
40
    {
41
        if (is_null($params)) {
42
            return $sql;
43
        }
44
45
        $paramSubstName = SQLBind::getParamModel($connData);
46
        foreach ($params as $key => $value) {
47
            $arg = str_replace("_", SQLBind::keyAdj($key), $paramSubstName);
48
49
            $count = 0;
50
            $sql = preg_replace("/(\[\[$key\]\]|:" . $key . "[\s\W]|:$key\$)/", $arg . ' ', $sql, -1, $count);
51
            if ($count === 0) {
52
                unset($params[$key]);
53
            }
54
        }
55
56
        $sql = preg_replace("/\[\[(.*?)\]\]/", "null", $sql);
57
58
        return array($sql, $params);
59
    }
60
61
    public static function keyAdj($key)
62
    {
63
        return str_replace(".", "_", $key);
64
    }
65
}
66