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

DolMemoryCollector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 9 2
A getWidgets() 0 12 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\MemoryCollector;
23
24
/**
25
 *  \file       htdocs/debugbar/class/DataCollector/DolMemoryCollector.php
26
 *  \brief      Class for debugbar collection
27
 *  \ingroup    debugbar
28
 */
29
30
/**
31
 * DolMemoryCollector class
32
 */
33
class DolMemoryCollector extends MemoryCollector
34
{
35
    /**
36
     *  Return value of indicator
37
     *
38
     * @return array       Array
39
     */
40
    public function collect()
41
    {
42
        global $conf;
43
44
        $this->updatePeakUsage();
45
        return array(
46
            'peak_usage' => $this->peakUsage,
47
            //'peak_usage_str' => $this->getDataFormatter()->formatBytes($this->peakUsage, 2)
48
            'peak_usage_str' => (empty($conf->dol_optimize_smallscreen) ? dol_print_size($this->peakUsage, 0) : dol_print_size($this->peakUsage, 1))
49
        );
50
    }
51
52
    /**
53
     *  Return widget settings
54
     *
55
     * @return array   Array
56
     */
57
    public function getWidgets()
58
    {
59
        global $langs;
60
61
        $langs->load("other");
62
63
        return array(
64
            "memory" => array(
65
                "icon" => "cogs",
66
                "tooltip" => $langs->transnoentities('MemoryUsage'),
67
                "map" => "memory.peak_usage_str",
68
                "default" => "'0B'"
69
            )
70
        );
71
    }
72
}
73