mambax7 /
pedigree
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | |||
| 3 | namespace XoopsModules\Pedigree; |
||
| 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 | * Pedigree class |
||
| 16 | * |
||
| 17 | * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
||
| 18 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||
| 19 | * @package XoopsModules\Pedigree\class |
||
| 20 | * @since 1.0 |
||
| 21 | * @author trabis <[email protected]> |
||
| 22 | * @author XOOPS Module Dev |
||
| 23 | */ |
||
| 24 | defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
||
| 25 | |||
| 26 | use \XoopsModules\Pedigree\Helper; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Class Pedigree |
||
| 30 | * @deprecated |
||
| 31 | */ |
||
| 32 | class Pedigree |
||
| 33 | { |
||
| 34 | public $dirname; |
||
| 35 | public $module; |
||
| 36 | public $handler; |
||
| 37 | public $config; |
||
| 38 | public $debug; |
||
| 39 | public $debugArray = []; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param $debug |
||
| 43 | */ |
||
| 44 | protected function __construct($debug) |
||
| 45 | { |
||
| 46 | $this->debug = $debug; |
||
| 47 | $moduleDirName = basename(dirname(__DIR__)); |
||
|
0 ignored issues
–
show
|
|||
| 48 | //parent::__construct($moduleDirName); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
86% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param bool $debug |
||
| 53 | * |
||
| 54 | * @return \XoopsModules\Pedigree\Pedigree |
||
| 55 | */ |
||
| 56 | public static function getInstance($debug = false) |
||
| 57 | { |
||
| 58 | static $instance; |
||
| 59 | if (null === $instance) { |
||
| 60 | $instance = new static($debug); |
||
| 61 | } |
||
| 62 | //error_log("instance: [" . print_r($istance,true) . "]"); |
||
| 63 | //phpinfo(); |
||
| 64 | //debug_print_backtrace (); |
||
| 65 | return $instance; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function getModule() |
||
| 69 | { |
||
| 70 | if (null === $this->module) { |
||
| 71 | $this->initModule(); |
||
| 72 | } |
||
| 73 | return $this->module; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * getConfig gets module configuration parameters |
||
| 78 | * |
||
| 79 | * @param string|null $name get a specific config paramter or all configs if $name = null |
||
| 80 | * |
||
| 81 | * @return array|string|null |
||
| 82 | */ |
||
| 83 | public function getConfig($name = null) |
||
| 84 | { |
||
| 85 | $helper = Helper::getInstance(); |
||
| 86 | |||
| 87 | if (null === $this->config) { |
||
| 88 | $this->initConfig(); |
||
| 89 | } |
||
| 90 | if (!$name) { |
||
| 91 | $helper->addLog('Getting all config'); |
||
| 92 | //$this->addLog('Getting all config'); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
86% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 93 | return $this->config; |
||
| 94 | } |
||
| 95 | if (!isset($this->config[$name])) { |
||
| 96 | $helper->addLog("ERROR :: CONFIG '{$name}' does not exist"); |
||
| 97 | //$this->addLog("ERROR :: CONFIG '{$name}' does not exist"); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
86% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 98 | return null; |
||
| 99 | } |
||
| 100 | $helper->addLog("Getting config '{$name}' : " . print_r($this->config[$name], true)); |
||
| 101 | //$this->addLog("Getting config '{$name}' : " . print_r($this->config[$name], true)); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
69% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 102 | |||
| 103 | |||
| 104 | return $this->config[$name]; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param string|null $name name of configuration option |
||
| 109 | * @param mixed|null $value value for config option |
||
| 110 | * |
||
| 111 | * @return mixed |
||
| 112 | */ |
||
| 113 | public function setConfig($name = null, $value = null) |
||
| 114 | { |
||
| 115 | /** @var \XoopsModules\Pedigree\Helper $helper */ |
||
| 116 | $helper = Helper::getInstance(); |
||
| 117 | |||
| 118 | if (null === $this->config) { |
||
| 119 | $this->initConfig(); |
||
| 120 | } |
||
| 121 | $this->config[$name] = $value; |
||
| 122 | $helper->addLog("Setting config '{$name}' : " . $this->config[$name]); |
||
| 123 | //$this->addLog("Setting config '{$name}' : " . $this->config[$name]); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
69% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 124 | |||
| 125 | |||
| 126 | return $this->config[$name]; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param $name |
||
| 131 | * |
||
| 132 | * @return mixed |
||
| 133 | */ |
||
| 134 | public function getHandler($name) |
||
| 135 | { |
||
| 136 | if (!isset($this->handler[$name . 'Handler'])) { |
||
| 137 | $this->initHandler($name); |
||
| 138 | } |
||
| 139 | $helper = Helper::getInstance(); |
||
| 140 | $helper->addLog("Getting handler '{$name}'"); |
||
| 141 | //$this->addLog("Getting handler '{$name}'"); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
86% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 142 | |||
| 143 | return $this->handler[$name . 'Handler']; |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * initModule instantiates XOOPS module object |
||
| 148 | * |
||
| 149 | * @return void |
||
| 150 | */ |
||
| 151 | public function initModule() |
||
| 152 | { |
||
| 153 | /** @var \XoopsModules\Pedigree\Helper $helper */ |
||
| 154 | $helper = Helper::getInstance(); |
||
| 155 | $this->module = $helper->getModule(); |
||
| 156 | $helper->addLog('INIT MODULE'); |
||
| 157 | /* |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
57% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 158 | |||
| 159 | global $xoopsModule; |
||
| 160 | if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $this->dirname) { |
||
| 161 | $this->module = $xoopsModule; |
||
| 162 | } else { |
||
| 163 | $hModule = xoops_getHandler('module'); |
||
| 164 | $this->module = $hModule->getByDirname($this->dirname); |
||
| 165 | } |
||
| 166 | $this->addLog('INIT MODULE'); |
||
| 167 | */ |
||
| 168 | |||
| 169 | } |
||
| 170 | |||
| 171 | public function initConfig() |
||
| 172 | { |
||
| 173 | /** @var \XoopsModules\Pedigree\Helper $helper */ |
||
| 174 | $helper = Helper::getInstance(); |
||
| 175 | $this->config = $helper->getConfig(); |
||
| 176 | /* |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 177 | $this->addLog('INIT CONFIG'); |
||
| 178 | $hModConfig = xoops_getHandler('config'); |
||
| 179 | $this->config = $hModConfig->getConfigsByCat(0, $this->getModule()->getVar('mid')); |
||
| 180 | */ |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param string $name name of the class/object for the handler |
||
| 185 | */ |
||
| 186 | public function initHandler($name) |
||
| 187 | { |
||
| 188 | /** @var \XoopsModules\Pedigree\Helper $helper */ |
||
| 189 | $helper = Helper::getInstance(); |
||
| 190 | $this->handler[$name . 'Handler'] = $helper->getHandler(ucfirst($name)); |
||
| 191 | /* |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 192 | $helper->addLog('INIT ' . ucase($name) . ' HANDLER'); |
||
| 193 | $this->addLog('INIT ' . ucase($name) . ' HANDLER'); |
||
| 194 | $this->handler[$name . 'Handler'] = xoops_getModuleHandler($name, $this->dirname); |
||
| 195 | */ |
||
| 196 | |||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param $log |
||
| 201 | */ |
||
| 202 | public function addLog($log) |
||
| 203 | { |
||
| 204 | if ($this->debug) { |
||
| 205 | /** @var \XoopsModules\Pedigree\Helper $helper */ |
||
| 206 | $helper = Helper::getInstance(); |
||
| 207 | $helper->addLog($log); |
||
| 208 | /* |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
73% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 209 | if (is_object($GLOBALS['xoopsLogger'])) { |
||
| 210 | $GLOBALS['xoopsLogger']->addExtra($this->module->name(), $log); |
||
| 211 | } |
||
| 212 | */ |
||
| 213 | |||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.