ResponseTemplatesHandler::insertQuery()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 19
rs 9.9
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @author       Eric Juden <[email protected]>
19
 * @author       XOOPS Development Team
20
 */
21
22
if (!\defined('XHELP_CLASS_PATH')) {
23
    exit();
24
}
25
// require_once XHELP_CLASS_PATH . '/BaseObjectHandler.php';
26
27
/**
28
 * xhelpResponseTemplatesHandler class
29
 *
30
 * ResponseTemplates Handler for xhelpResponseTemplates class
31
 *
32
 * @author  Eric Juden <[email protected]> &
33
 */
34
class ResponseTemplatesHandler extends BaseObjectHandler
35
{
36
    /**
37
     * Name of child class
38
     *
39
     * @var string
40
     */
41
    public $classname = ResponseTemplates::class;
42
    /**
43
     * DB table name
44
     *
45
     * @var string
46
     */
47
    public $dbtable = 'xhelp_responsetemplates';
48
49
    private const TABLE = 'xhelp_responsetemplates';
50
    private const ENTITY = ResponseTemplates::class;
51
    private const ENTITYNAME = 'ResponseTemplates';
52
    private const KEYNAME = 'id';
53
    private const IDENTIFIER = 'name';
54
55
    /**
56
     * Constructor
57
     *
58
     * @param \XoopsMySQLDatabase|null $db reference to a xoopsDB object
59
     */
60
    public function __construct(\XoopsMySQLDatabase $db = null)
61
    {
62
        $this->init($db);
63
        $this->helper = Helper::getInstance();
64
        parent::__construct($db, static::TABLE, static::ENTITY, static::KEYNAME, static::IDENTIFIER);
65
    }
66
67
    /**
68
     * @param \XoopsObject $object
69
     * @return string
70
     */
71
    public function insertQuery(\XoopsObject $object): string
72
    {
73
        //TODO mb replace with individual variables
74
        // Copy all object vars into local variables
75
        foreach ($object->cleanVars as $k => $v) {
76
            ${$k} = $v;
77
        }
78
79
        $sql = \sprintf(
80
            'INSERT INTO `%s` (id, uid, NAME, response)
81
                VALUES (%u, %u, %s, %s)',
82
            $this->db->prefix($this->dbtable),
83
            $id,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
84
            $uid,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $uid seems to be never defined.
Loading history...
85
            $this->db->quoteString($name),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
86
            $this->db->quoteString($response)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $response seems to be never defined.
Loading history...
87
        );
88
89
        return $sql;
90
    }
91
92
    /**
93
     * @param \XoopsObject $object
94
     * @return string
95
     */
96
    public function updateQuery(\XoopsObject $object): string
97
    {
98
        //TODO mb replace with individual variables
99
        // Copy all object vars into local variables
100
        foreach ($object->cleanVars as $k => $v) {
101
            ${$k} = $v;
102
        }
103
104
        $sql = \sprintf('UPDATE `%s` SET uid = %u, NAME = %s, response = %s WHERE id = %u', $this->db->prefix($this->dbtable), $uid, $this->db->quoteString($name), $this->db->quoteString($response), $id);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $uid seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $response seems to be never defined.
Loading history...
105
106
        return $sql;
107
    }
108
109
    /**
110
     * @param \XoopsObject $object
111
     * @return string
112
     */
113
    public function deleteQuery(\XoopsObject $object): string
114
    {
115
        $sql = \sprintf('DELETE FROM `%s` WHERE id = %u', $this->db->prefix($this->dbtable), $object->getVar('id'));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar('id') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

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

115
        $sql = \sprintf('DELETE FROM `%s` WHERE id = %u', $this->db->prefix($this->dbtable), /** @scrutinizer ignore-type */ $object->getVar('id'));
Loading history...
116
117
        return $sql;
118
    }
119
}
120