Passed
Push — MODEL_LIB_240928 ( d6fbb6...55f3e4 )
by Rafael
49:14
created

DolConfigCollector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A objectToArray() 0 11 5
A collect() 0 5 1
A getWidgets() 0 10 1
A getConfig() 0 21 1
1
<?php
2
3
/* Copyright (C) 2023       Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2024       Rafael San José             <[email protected]>
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace Dolibarr\Tools\DebugBarCollector;
21
22
use DebugBar\DataCollector\ConfigCollector;
23
24
/**
25
 *  \file       htdocs/debugbar/class/DataCollector/DolConfigCollector.php
26
 *  \brief      Class for debugbar collection
27
 *  \ingroup    debugbar
28
 */
29
30
/**
31
 * DolConfigCollector class
32
 */
33
class DolConfigCollector extends ConfigCollector
34
{
35
    /**
36
     *  Return widget settings
37
     *
38
     * @return array      Array
39
     */
40
    public function getWidgets()
41
    {
42
        global $langs;
43
44
        return array(
45
            $langs->transnoentities('Config') => array(
46
                "icon" => "gear",
47
                "widget" => "PhpDebugBar.Widgets.VariableListWidget",
48
                "map" => $this->getName(),
49
                "default" => "{}"
50
            )
51
        );
52
    }
53
54
    /**
55
     *  Return collected data
56
     *
57
     * @return    array   Array of collected data
58
     */
59
    public function collect()
60
    {
61
        $this->data = $this->getConfig();
62
63
        return parent::collect();
64
    }
65
66
    /**
67
     * Returns an array with config data
68
     *
69
     * @return array       Array of config
70
     */
71
    protected function getConfig()
72
    {
73
        global $conf, $user;
74
75
        // Get constants
76
        $const = get_defined_constants(true);
77
78
        $config = array(
79
            'Dolibarr' => array(
80
                'const' => $const['user'],
81
                '$conf' => $this->objectToArray($conf),
82
                '$user' => $this->objectToArray($user)
83
            ),
84
            'PHP' => array(
85
                'version' => PHP_VERSION,
86
                'interface' => PHP_SAPI,
87
                'os' => PHP_OS
88
            )
89
        );
90
91
        return $config;
92
    }
93
94
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
95
96
    /**
97
     * Convert an object to array
98
     *
99
     * @param mixed $obj Object
100
     * @return array               Array
101
     */
102
    protected function objectToArray($obj)
103
    {
104
        // phpcs:enable
105
        $arr = array();
106
        $_arr = is_object($obj) ? get_object_vars($obj) : $obj;
107
        foreach ($_arr as $key => $val) {
108
            $val = (is_array($val) || is_object($val)) ? $this->objectToArray($val) : $val;
109
            $arr[$key] = $val;
110
        }
111
112
        return $arr;
113
    }
114
}
115