Completed
Push — master ( 00e474...9d3fbd )
by Michael
04:26
created

OledrionHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 14 4
A __construct() 0 4 1
A getInstance() 0 9 2
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
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link http://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
20
/**
21
 * Chargement des handlers utilisés par le module
22
 */
23
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
24
25
class OledrionHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
26
{
27
    /**
28
     * Contient la liste des handlers disponibles
29
     *
30
     * @var array
31
     */
32
    private $handlersNames = array(
33
        'oledrion_manufacturer',
34
        'oledrion_products',
35
        'oledrion_productsmanu',
36
        'oledrion_caddy',
37
        'oledrion_cat',
38
        'oledrion_commands',
39
        'oledrion_related',
40
        'oledrion_vat',
41
        'oledrion_votedata',
42
        'oledrion_discounts',
43
        'oledrion_vendors',
44
        'oledrion_files',
45
        'oledrion_persistent_cart',
46
        'oledrion_gateways_options',
47
        'oledrion_attributes',
48
        'oledrion_caddy_attributes',
49
        'oledrion_products_list',
50
        'oledrion_lists',
51
        'oledrion_delivery',
52
        'oledrion_location',
53
        'oledrion_packing',
54
        'oledrion_payment',
55
        'oledrion_location_delivery',
56
        'oledrion_delivery_payment',
57
        'oledrion_payment_log'
58
    );
59
60
    /**
61
     * Contient l'unique instance de l'objet
62
     * @var object
63
     */
64
    private static $instance = false;
0 ignored issues
show
Unused Code introduced by
The property $instance is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
65
66
    /**
67
     * Réceptacle des handlers
68
     *
69
     * @var array
70
     */
71
    public $handlers = null;
72
73
    /**
74
     * Méthode chargée de renvoyer les handlers de données en les chargeant à la volée
75
     *
76
     * @param  string $name
77
     * @return mixed  Null si on échoue, sinon l'objet demandé
78
     */
79
    public function __get($name)
80
    {
81
        if (substr($name, 0, 2) !== 'h_') {
82
            return null;
83
        }
84
        if (!in_array(substr($name, 2), $this->handlersNames)) {
85
            return null;
86
        }
87
        if (!isset($this->handlersNames[$name])) {
88
            $this->handlers[$name] = xoops_getModuleHandler(substr($name, 2), OLEDRION_DIRNAME);
89
        }
90
91
        return $this->handlers[$name];
92
    }
93
94
    /**
95
     * OledrionHandler constructor.
96
     */
97
    private function __construct()
98
    {
99
        $this->handlers = array();
100
    }
101
102
    /**
103
     * Retourne l'instance unique de la classe
104
     *
105
     * @return object
106
     */
107
    public static function getInstance()
108
    {
109
        static $instance;
110
        if (null === $instance) {
111
            $instance = new static();
112
        }
113
114
        return $instance;
115
    }
116
}
117