Passed
Pull Request — master (#18)
by Michael
04:31
created

Option   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
c 0
b 0
f 0
dl 0
loc 138
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getStaticOptHandler() 0 9 2
A getAllByPollId() 0 7 1
A store() 0 6 1
A Option() 0 3 1
A resetCountByPollId() 0 8 1
A deleteByPollId() 0 7 1
A __construct() 0 21 3
1
<?php
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
 * Poll Option class for the XoopsPoll Module
31
 *
32
 * @copyright ::  {@link https://xoops.org/ XOOPS Project}
33
 * @license   ::  {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
34
 * @package   ::  xoopspoll
35
 * @subpackage::  class
36
 * @since     ::  1.0
37
 * @author    ::  {@link http://www.myweb.ne.jp/ Kazumi Ono (AKA onokazu)}
38
 */
39
40
use XoopsModules\Xoopspoll;
41
42
 /**
43
 * Class Option
44
 * @package XoopsModules\Xoopspoll
45
 */
46
class Option extends \XoopsObject
47
{
48
    /**
49
     * database connection object
50
     * @var \XoopsDatabasefactory
51
     */
52
    //    protected $db;
53
    /**
54
     * holds option object
55
     * @var Option
56
     */
57
    protected $option;
58
    /**
59
     * Option Handler to be used to manipulate poll options
60
     * @var OptionHandler
61
     */
62
    protected $optionHandler;
63
64
    // constructor
65
66
    /**
67
     * @param int|null $id poll id
68
     */
69
    public function __construct($id = null)
70
    {
71
        parent::__construct();
72
        //        xoops_load('constants', 'xoopspoll');
73
        //        $this->db = \XoopsDatabaseFactory::getDatabaseConnection();
74
        $this->initVar('option_id', \XOBJ_DTYPE_INT, null, false);
75
        $this->initVar('poll_id', \XOBJ_DTYPE_INT, null, true);
76
        $this->initVar('option_text', \XOBJ_DTYPE_TXTBOX, null, true, 255);
77
        $this->initVar('option_count', \XOBJ_DTYPE_INT, 0, false);
78
        $this->initVar('option_color', \XOBJ_DTYPE_OTHER, null, false);
79
80
        /**
81
         * {@internal The following is provided for backward compatibility with newbb/xforum}
82
         */
83
        $this->optHandler = $this->getStaticOptHandler();
0 ignored issues
show
Bug Best Practice introduced by
The property optHandler does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
84
        if (!empty($id)) {
85
            if (\is_array($id)) {
0 ignored issues
show
introduced by
The condition is_array($id) is always false.
Loading history...
86
                $this->option = $this->optHandler->create();
87
                $this->option->assignVars($id);
88
            } else {
89
                $this->option = $this->optHandler->get($id);
90
            }
91
        }
92
    }
93
94
    /**
95
     * @param int|null $id poll id
96
     * @return void
97
     * @deprecated since PHP4 died - use __construct
98
     */
99
    public function Option($id = null)
100
    {
101
        $this->__construct($id);
102
    }
103
    /**#@+
104
     * @deprecated since Xoopspoll 1.40, please @see XoopspollOptionHandler & @see XoopspollOption
105
     */
106
    /**
107
     *
108
     * Stores object into the database
109
     * @uses XoopsPersistableObjectHandler::insert
110
     * @return mixed
111
     * @deprecated since Xoopspoll 1.40, please @see XoopspollOptionHandler & @see XoopspollOption
112
     */
113
    public function store()
114
    {
115
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
116
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use Poll and PollHandler classes instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}");
117
118
        return $this->optHandler->insert($this->option);
119
    }
120
121
    /**
122
     * Delete all the poll options for a specific poll
123
     * @uses XoopsPersistableObjectHandler::deleteAll
124
     * @param  int   $pid is used to delete all options by this id
125
     * @return mixed results of deleting objects from database
126
     * @uses XoopsPersistableObjectHandler::deleteAll
127
     */
128
    public function deleteByPollId($pid)
129
    {
130
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
131
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use PollHandler::' . __METHOD__ . ' instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}");
132
        $criteria    = new \Criteria('poll_id', (int)$pid, '=');
133
134
        return $this->optHandler->deleteAll($criteria);
135
    }
136
137
    /**
138
     * Get all options for a particular poll
139
     * @uses XoopsPersistableObjectHandler::getAll
140
     * @param  unknown $pid
0 ignored issues
show
Bug introduced by
The type XoopsModules\Xoopspoll\unknown was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
141
     * @return mixed   results of getting objects from database
142
     * @uses XoopsPersistableObjectHandler::getAll
143
     */
144
    public function getAllByPollId($pid)
145
    {
146
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
147
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use PollHandler::' . __METHOD__ . ' instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}");
148
        $criteria    = new \Criteria('poll_id', (int)$pid, '=');
149
150
        return $this->optHandler->getAll($criteria);
151
    }
152
153
    /**
154
     * Reset the poll's options vote count
155
     * @param unknown_type $pid
0 ignored issues
show
Bug introduced by
The type XoopsModules\Xoopspoll\unknown_type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
156
     * @uses XoopsPersistableObjectHandler::updateAll
157
     * @return mixed results of the object(s) update
158
     * @uses XoopsPersistableObjectHandler::updateAll
159
     */
160
    public function resetCountByPollId($pid)
161
    {
162
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
163
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __METHOD__ . ' is deprecated since Xoopspoll 1.40, please use PollHandler::' . __METHOD__ . ' instead.' . ". Called from {$trace[0]['file']}line {$trace[0]['line']}");
164
        $soptHandler = $this->getStaticOptHandler();
165
        $criteria    = new \Criteria('poll_id', (int)$pid, '=');
166
167
        return $soptHandler->updateAll('option_count', 0, $criteria);
168
    }
169
170
    /**
171
     * Get a static Option Handler to be used to manipulate poll options
172
     * @return mixed handler object returned on success, false on failure
173
     * @uses xoops_getModuleHandler
174
     */
175
    private function getStaticOptHandler()
176
    {
177
        static $optionHandler;
178
179
        if (!isset($optionHandler)) {
180
            $optionHandler = Xoopspoll\Helper::getInstance()->getHandler('Option');
181
    }
182
183
        return $optionHandler;
184
        }
185
186
    /**#@-*/
187
}
188