TrelloDBController::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 3
dl 0
loc 6
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Publisher;
4
5
/**
6
 * Class TrelloDBController
7
 */
8
class TrelloDBController
9
{
10
    /** @var \XoopsMySQLDatabase */
11
    private $db;
12
13
    /**
14
     * TrelloDBController constructor.
15
     * @param \XoopsMySQLDatabase $xoopsDb
16
     */
17
    public function __construct($xoopsDb)
18
    {
19
        $this->db = $xoopsDb;
20
    }
21
22
    /**
23
     * @param string $query
24
     * @return mixed
25
     */
26
    public function runBaseQuery($query)
27
    {
28
        $resultset = [];
29
        $result    = $this->db->conn->query($query);
30
        if ($result->num_rows > 0) {
31
            while (null !== ($row = $result->fetch_assoc())) {
32
                $resultset[] = $row;
33
            }
34
        }
35
36
        return $resultset;
37
    }
38
39
    /**
40
     * @param string $query
41
     * @param string $paramType
42
     * @param array  $paramValueArray
43
     * @return mixed
44
     */
45
    public function runQuery($query, $paramType, $paramValueArray)
46
    {
47
        /** @var mysqli_stmt $sql */
48
        $sql = $this->db->conn->prepare($query);
0 ignored issues
show
Bug introduced by
The method prepare() does not exist on XoopsDatabase. ( Ignorable by Annotation )

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

48
        /** @scrutinizer ignore-call */ 
49
        $sql = $this->db->conn->prepare($query);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
        $this->bindQueryParams($sql, $paramType, $paramValueArray);
50
        $sql->execute();
51
        $result = $sql->get_result();
52
53
        if ($result->num_rows > 0) {
54
            while (null !== ($row = $result->fetch_assoc())) {
55
                $resultset[] = $row;
56
            }
57
        }
58
59
        if (!empty($resultset)) {
60
            return $resultset;
61
        }
62
63
        return false;
64
    }
65
66
    /**
67
     * @param mysqli_stmt $sql
0 ignored issues
show
Bug introduced by
The type XoopsModules\Publisher\mysqli_stmt was not found. Did you mean mysqli_stmt? If so, make sure to prefix the type with \.
Loading history...
68
     * @param string      $paramType
69
     * @param array       $paramValueArray
70
     */
71
    public function bindQueryParams($sql, $paramType, $paramValueArray): void
72
    {
73
        $paramValueReference   = [];
74
        $paramValueReference[] = &$paramType;
75
        foreach ($paramValueArray as $i => $iValue) {
76
            $paramValueReference[] = &$iValue;
77
        }
78
        \call_user_func_array(
79
            [
80
                $sql,
81
                'bind_param',
82
            ],
83
            $paramValueReference
84
        );
85
    }
86
87
    /**
88
     * @param string $query
89
     * @param string $paramType
90
     * @param array  $paramValueArray
91
     */
92
    public function insert($query, $paramType, $paramValueArray): void
93
    {
94
        /** @var mysqli_stmt $sql */
95
        $sql = $this->db->conn->prepare($query);
96
        $this->bindQueryParams($sql, $paramType, $paramValueArray);
97
        $sql->execute();
98
    }
99
100
    /**
101
     * @param string $query
102
     * @param string $paramType
103
     * @param array  $paramValueArray
104
     */
105
    public function update($query, $paramType, $paramValueArray): void
106
    {
107
        /** @var mysqli_stmt $sql */
108
        $sql = $this->db->conn->prepare($query);
109
        $this->bindQueryParams($sql, $paramType, $paramValueArray);
110
        $sql->execute();
111
    }
112
}
113