Completed
Push — master ( a28409...20baf9 )
by Michael
01:24
created

class/helper.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * contact module for xoops
13
 *
14
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
15
 * @license         GPL 2.0 or later
16
 * @package         contact
17
 * @since           1.0
18
 * @min_xoops       2.5.7
19
 * @author          Goffy (xoops.wedega.com) - Email:<[email protected]> - Website:<http://xoops.wedega.com>
20
 */
21
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
22
23
/**
24
 * Class ContactHelper
25
 */
26
class ContactHelper
27
{
28
    /**
29
     * @var string
30
     */
31
    private $dirname;
32
    /**
33
     * @var string
34
     */
35
    private $module;
36
    /**
37
     * @var string
38
     */
39
    private $handler;
40
    /**
41
     * @var string
42
     */
43
    private $config;
44
    /**
45
     * @var string
46
     */
47
    private $debug;
48
    /**
49
     * @var array
50
     */
51
    private $debugArray = array();
52
    /*
53
    *  @protected function constructor class
54
    *  @param mixed $debug
55
    */
56
    /**
57
     * ContactHelper constructor.
58
     * @param $debug
59
     */
60
    protected function __construct($debug)
61
    {
62
        $this->debug = $debug;
63
        $this->dirname =  basename(dirname(__DIR__));
64
    }
65
    /*
66
    *  @static function &getInstance
67
    *  @param mixed $debug
68
    */
69
    /**
70
     * @param bool $debug
71
     * @return bool|ContactHelper
72
     */
73
    public static function &getInstance($debug = false)
74
    {
75
        static $instance = false;
76
        if (!$instance) {
77
            $instance = new self($debug);
78
        }
79
        return $instance;
80
    }
81
    /*
82
    *  @static function getModule
83
    *  @param null
84
    */
85
    /**
86
     * @return string
87
     */
88
    public function &getModule()
89
    {
90
        if ($this->module === null) {
91
            $this->initModule();
92
        }
93
        return $this->module;
94
    }
95
    /*
96
    *  @static function getConfig
97
    *  @param string $name
98
    */
99
    /**
100
     * @param null $name
101
     * @return null|string
102
     */
103
    public function getConfig($name = null)
104
    {
105
        if ($this->config === null) {
106
            $this->initConfig();
107
        }
108
        if (!$name) {
109
            $this->addLog('Getting all config');
110
            return $this->config;
111
        }
112
        if (!isset($this->config[$name])) {
113
            $this->addLog("ERROR :: CONFIG '{$name}' does not exist");
114
            return null;
115
        }
116
        $this->addLog("Getting config '{$name}' : " . $this->config[$name]);
117
        return $this->config[$name];
118
    }
119
    /*
120
    *  @static function setConfig
121
    *  @param string $name
122
    *  @param mixed $value
123
    */
124
    /**
125
     * @param null $name
126
     * @param null $value
127
     * @return mixed
128
     */
129
    public function setConfig($name = null, $value = null)
130
    {
131
        if ($this->config === null) {
132
            $this->initConfig();
133
        }
134
        $this->config[$name] = $value;
135
        $this->addLog("Setting config '{$name}' : " . $this->config[$name]);
136
        return $this->config[$name];
137
    }
138
    /*
139
    *  @static function getHandler
140
    *  @param string $name
141
    */
142
    /**
143
     * @param $name
144
     * @return mixed
145
     */
146
    public function &getHandler($name)
147
    {
148
        if (!isset($this->handler[$name . 'Handler'])) {
149
            $this->initHandler($name);
150
        }
151
        $this->addLog("Getting handler '{$name}'");
152
        return $this->handler[$name . 'Handler'];
153
    }
154
    /*
155
    *  @static function initModule
156
    *  @param null
157
    */
158
    public function initModule()
159
    {
160
        global $xoopsModule;
161
        if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $this->dirname) {
162
            $this->module = $xoopsModule;
0 ignored issues
show
Documentation Bug introduced by
It seems like $xoopsModule of type object is incompatible with the declared type string of property $module.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
163
        } else {
164
            /** @var XoopsModule $hModule */
165
            $hModule = xoops_getHandler('module');
166
            $this->module = $hModule::getByDirname($this->dirname);
167
        }
168
        $this->addLog('INIT MODULE');
169
    }
170
    /*
171
    *  @static function initConfig
172
    *  @param null
173
    */
174
    public function initConfig()
175
    {
176
        $this->addLog('INIT CONFIG');
177
        /** @var XoopsConfigHandler $hModConfig */
178
        $hModConfig = xoops_getHandler('config');
179
        $this->config = $hModConfig->getConfigsByCat(0, $this->getModule()->getVar('mid'));
0 ignored issues
show
The method getVar cannot be called on $this->getModule() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
180
    }
181
    /*
182
    *  @static function initHandler
183
    *  @param string $name
184
    */
185
    /**
186
     * @param $name
187
     */
188
    public function initHandler($name)
189
    {
190
        $this->addLog('INIT ' . $name . ' HANDLER');
191
        $this->handler[$name . 'Handler'] = xoops_getModuleHandler($name, $this->dirname);
192
    }
193
    /*
194
    *  @static function addLog
195
    *  @param string $log
196
    */
197
    /**
198
     * @param $log
199
     */
200
    public function addLog($log)
201
    {
202
        if ($this->debug) {
203
            if (is_object($GLOBALS['xoopsLogger'])) {
204
                $GLOBALS['xoopsLogger']->addExtra($this->module->name(), $log);
0 ignored issues
show
The method name cannot be called on $this->module (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
205
            }
206
        }
207
    }
208
}
209