LogMessageHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 76
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A updateQuery() 0 11 2
A __construct() 0 5 1
A insertQuery() 0 11 2
A deleteQuery() 0 5 1
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
//
26
// require_once XHELP_CLASS_PATH . '/BaseObjectHandler.php';
27
28
/**
29
 * LogMessageHandler class
30
 *
31
 * LogMessage Handler for LogMessage class
32
 *
33
 * @author  Eric Juden <[email protected]> &
34
 */
35
class LogMessageHandler extends BaseObjectHandler
36
{
37
    /**
38
     * Name of child class
39
     *
40
     * @var string
41
     */
42
    public $classname = LogMessage::class;
43
    /**
44
     * DB table name
45
     *
46
     * @var string
47
     */
48
    public $dbtable = 'xhelp_logmessages';
49
50
    private const TABLE = 'xhelp_logmessages';
51
    private const ENTITY = LogMessage::class;
52
    private const ENTITYNAME = 'LogMessage';
53
    private const KEYNAME = 'id';
54
    private const IDENTIFIER = 'ticketid';
55
56
    /**
57
     * Constructor
58
     *
59
     * @param \XoopsMySQLDatabase|null $db reference to a xoopsDB object
60
     */
61
    public function __construct(\XoopsMySQLDatabase $db = null)
62
    {
63
        $this->init($db);
64
        $this->helper = Helper::getInstance();
65
        parent::__construct($db, static::TABLE, static::ENTITY, static::KEYNAME, static::IDENTIFIER);
66
    }
67
68
    /**
69
     * @param \XoopsObject $object
70
     * @return string
71
     */
72
    public function insertQuery(\XoopsObject $object): string
73
    {
74
        //TODO mb replace with individual variables
75
        // Copy all object vars into local variables
76
        foreach ($object->cleanVars as $k => $v) {
77
            ${$k} = $v;
78
        }
79
80
        $sql = \sprintf('INSERT INTO `%s` (id, uid, ticketid, lastUpdated, ACTION) VALUES (%u, %u, %u, %u, %s)', $this->db->prefix($this->dbtable), $id, $uid, $ticketid, \time(), $this->db->quoteString($action));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $uid seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $ticketid seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $action seems to be never defined.
Loading history...
81
82
        return $sql;
83
    }
84
85
    /**
86
     * @param \XoopsObject $object
87
     * @return string
88
     */
89
    public function updateQuery(\XoopsObject $object): string
90
    {
91
        //TODO mb replace with individual variables
92
        // Copy all object vars into local variables
93
        foreach ($object->cleanVars as $k => $v) {
94
            ${$k} = $v;
95
        }
96
97
        $sql = \sprintf('UPDATE `%s` SET uid = %u, ticketid = %u, lastUpdated = %u, ACTION = %s WHERE id = %u', $this->db->prefix($this->dbtable), $uid, $ticketid, \time(), $this->db->quoteString($action), $id);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $ticketid seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $action seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $uid seems to be never defined.
Loading history...
98
99
        return $sql;
100
    }
101
102
    /**
103
     * @param \XoopsObject $object
104
     * @return string
105
     */
106
    public function deleteQuery(\XoopsObject $object): string
107
    {
108
        $sql = \sprintf('DELETE FROM `%s` WHERE id = %u', $this->db->prefix($this->dbtable), $object->getVar($this->idfield));
0 ignored issues
show
Bug introduced by
It seems like $object->getVar($this->idfield) 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

108
        $sql = \sprintf('DELETE FROM `%s` WHERE id = %u', $this->db->prefix($this->dbtable), /** @scrutinizer ignore-type */ $object->getVar($this->idfield));
Loading history...
109
110
        return $sql;
111
    }
112
}
113