Log   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 34
c 0
b 0
f 0
dl 0
loc 94
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A hasVoted() 0 9 1
A getStaticLogHandler() 0 11 2
A deleteByOptionId() 0 10 1
A deleteByPollId() 0 9 1
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopspoll;
4
5
/*
6
               XOOPS - PHP Content Management System
7
                   Copyright (c) 2000-2020 XOOPS.org
8
                      <https://xoops.org>
9
 This program is free software; you can redistribute it and/or modify
10
 it under the terms of the GNU General Public License as published by
11
 the Free Software Foundation; either version 2 of the License, or
12
 (at your option) any later version.
13
14
 You may not change or alter any portion of this comment or credits
15
 of supporting developers from this source code or any supporting
16
 source code which is considered copyrighted (c) material of the
17
 original comment or credit authors.
18
19
 This program is distributed in the hope that it will be useful,
20
 but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 GNU General Public License for more details.
23
24
 You should have received a copy of the GNU General Public License
25
 along with this program; if not, write to the Free Software
26
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
27
*/
28
29
/**
30
 * Log class for the XoopsPoll Module
31
 *
32
 * @copyright ::  {@link https://xoops.org/ XOOPS Project}
33
 * @license   ::  {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later}
34
 * @subpackage::  class
35
 * @since     ::  1.40
36
 * @author    ::  {@link https://www.myweb.ne.jp/ Kazumi Ono (AKA onokazu)}
37
 **/
38
39
use XoopsModules\Xoopspoll\{
40
    Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Xoopspoll\Helper. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
41
};
42
43
/**
44
 * Log() class definition for Log Objects
45
 * @author:: zyspec <[email protected]>
46
 * @uses  ::   xoops_getModuleHandler poll module handler for class use
47
 */
48
class Log extends \XoopsObject
49
{
50
    public int    $log_id;
51
    public int    $poll_id;
52
    public int    $option_id;
53
    public string $ip;
54
    public int    $user_id;
55
    public int    $time;
56
57
    //  class Log extends \XoopsObject {
58
    //    var $db;
59
60
    /**
61
     * Constructor
62
     * @param int|null $id
63
     */
64
    public function __construct(int $id = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

64
    public function __construct(/** @scrutinizer ignore-unused */ int $id = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        parent::__construct();
67
        $this->initVar('log_id', \XOBJ_DTYPE_INT, 0);
68
        $this->initVar('poll_id', \XOBJ_DTYPE_INT, null, true);
69
        $this->initVar('option_id', \XOBJ_DTYPE_INT, null, true);
70
        $this->initVar('ip', \XOBJ_DTYPE_OTHER, null);
71
        $this->initVar('user_id', \XOBJ_DTYPE_INT, 0);
72
        $this->initVar('time', \XOBJ_DTYPE_INT, null);
73
//        if (!empty($id) && \is_array($id)) {
74
//            $this->assignVars($id);
75
//        }
76
    }
77
78
    /**
79
     * The following method is provided for backward compatibility with newbb
80
     * @param int $pid
81
     * @return mixed
82
     * @deprecated since Xoopspoll 1.40, please use LogHandler & Log
83
     */
84
    public static function deleteByPollId(int $pid): mixed
85
    {
86
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
87
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
88
        /** @var LogHandler $slogHandler */
89
        $slogHandler = self::getStaticLogHandler();
90
        $criteria    = new \Criteria('poll_id', (int)$pid, '=');
91
92
        return $slogHandler->deleteAll($criteria);
93
    }
94
95
    /**
96
     * @param int $opt_id
97
     * @return mixed
98
     */
99
    public static function deleteByOptionId(int $opt_id): mixed
100
    {
101
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
102
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
103
104
        /** @var LogHandler $slogHandler */
105
        $slogHandler = self::getStaticLogHandler();
106
        $criteria    = new \Criteria('option_id', (int)$opt_id, '=');
107
108
        return $slogHandler->deleteAll($criteria);
109
    }
110
111
    /**
112
     * @param int $pid
113
     * @param string $ip
114
     * @param int $uid
115
     * @return mixed
116
     */
117
    public static function hasVoted(int $pid, string $ip, int $uid): mixed
118
    {
119
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
120
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
121
122
        /** @var LogHandler $slogHandler */
123
        $slogHandler = self::getStaticLogHandler();
124
125
        return $slogHandler->hasVoted($pid, $ip, $uid);
126
    }
127
128
    /**
129
     * @return bool
130
     */
131
    private static function getStaticLogHandler(): bool
132
    {
133
        static $logHandler;
134
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
135
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
136
137
        if (!isset($logHandler)) {
138
            $logHandler = Helper::getInstance()->getHandler('Log');
139
        }
140
141
        return $logHandler;
142
    }
143
    /**#@-*/
144
}
145