Completed
Push — master ( c8eead...62889a )
by Michael
04:13
created

class/pedigree.php (2 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 27 and the first side effect is on line 22.

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.

Loading history...
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
 *  PedigreePedigree class
13
 *
14
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
15
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @package         Class
17
 * @subpackage      Utils
18
 * @since           1.0
19
 * @author          trabis <[email protected]>
20
 * @version         $Id: pedigree.php 12841 2014-11-12 13:14:13Z beckmi $
21
 */
22
defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
23
24
/**
25
 * Class PedigreePedigree
26
 */
27
class PedigreePedigree
28
{
29
    var $dirname;
30
    var $module;
31
    var $handler;
32
    var $config;
33
    var $debug;
34
    var $debugArray = array();
35
36
    /**
37
     * @param $debug
38
     */
39
    protected function __construct($debug)
40
    {
41
        $this->debug   = $debug;
42
        $this->dirname = basename(dirname(__DIR__));
43
    }
44
45
    /**
46
     * @param bool $debug
47
     *
48
     * @return PedigreePedigree
49
     */
50
    static function &getInstance($debug = false)
51
    {
52
        static $instance = false;
53
        if (!$instance) {
54
            $instance = new self($debug);
55
        }
56
//error_log("istance: [" . print_r($istance,true) . "]");
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
57
//phpinfo();
58
//debug_print_backtrace ();
59
        return $instance;
60
    }
61
62
    function &getModule()
63
    {
64
        if ($this->module == null) {
65
            $this->initModule();
66
        }
67
68
        return $this->module;
69
    }
70
71
    /**
72
     * @param null $name
73
     *
74
     * @return null
75
     */
76
    function getConfig($name = null)
77
    {
78
        if ($this->config == null) {
79
            $this->initConfig();
80
        }
81
        if (!$name) {
82
            $this->addLog("Getting all config");
83
84
            return $this->config;
85
        }
86
        if (!isset($this->config[$name])) {
87
            $this->addLog("ERROR :: CONFIG '{$name}' does not exist");
88
89
            return null;
90
        }
91
        $this->addLog("Getting config '{$name}' : " . print_r($this->config[$name], true));
92
93
        return $this->config[$name];
94
    }
95
96
    /**
97
     * @param null $name
98
     * @param null $value
99
     *
100
     * @return mixed
101
     */
102
    function setConfig($name = null, $value = null)
103
    {
104
        if ($this->config == null) {
105
            $this->initConfig();
106
        }
107
        $this->config[$name] = $value;
108
        $this->addLog("Setting config '{$name}' : " . $this->config[$name]);
109
110
        return $this->config[$name];
111
    }
112
113
    /**
114
     * @param $name
115
     *
116
     * @return mixed
117
     */
118
    function &getHandler($name)
119
    {
120
        if (!isset($this->handler[$name . '_handler'])) {
121
            $this->initHandler($name);
122
        }
123
        $this->addLog("Getting handler '{$name}'");
124
125
        return $this->handler[$name . '_handler'];
126
    }
127
128
    function initModule()
129
    {
130
        global $xoopsModule;
131
        if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $this->dirname) {
132
            $this->module = $xoopsModule;
133
        } else {
134
            $hModule      = xoops_gethandler('module');
135
            $this->module = $hModule->getByDirname($this->dirname);
136
        }
137
        $this->addLog('INIT MODULE');
138
    }
139
140
    function initConfig()
141
    {
142
        $this->addLog('INIT CONFIG');
143
        $hModConfig   = xoops_gethandler('config');
144
        $this->config = $hModConfig->getConfigsByCat(0, $this->getModule()->getVar('mid'));
145
    }
146
147
    /**
148
     * @param $name
149
     */
150
    function initHandler($name)
151
    {
152
        $this->addLog('INIT ' . $name . ' HANDLER');
153
        $this->handler[$name . '_handler'] = xoops_getModuleHandler($name, $this->dirname);
154
    }
155
156
    /**
157
     * @param $log
158
     */
159
    function addLog($log)
160
    {
161
        if ($this->debug) {
162
            if (is_object($GLOBALS['xoopsLogger'])) {
163
                $GLOBALS['xoopsLogger']->addExtra($this->module->name(), $log);
164
            }
165
        }
166
    }
167
}
168