Passed
Pull Request — master (#215)
by
unknown
02:23
created

FileDumper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 20
dl 0
loc 33
rs 10
c 2
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A DUMP() 0 25 2
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Util;
22
23
class FileDumper
24
{
25
    private const LINE   = "------------------------------------------------------------------------------------------------------------------------\n";
26
    private const FOLDER = './var/dump/';
27
28
    /**
29
     * @param mixed $var
30
     */
31
    public static function DUMP($var): void
32
    {
33
        // Define contents
34
        $calledFrom = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
35
        $headline1  = "{$calledFrom['file']} (Line: {$calledFrom['line']})"; // @phpstan-ignore-line
36
        $headline2  = "{$calledFrom['class']}::{$calledFrom['function']}()"; // @phpstan-ignore-line
37
        $dateTime   = (new \DateTime())->format('Y_m_d_\T_H_i_s.u');
38
        $filename   = "dump_{$dateTime}.txt";
39
40
        // Create folder if not exist
41
        if (!file_exists(self::FOLDER)) {
42
            mkdir(self::FOLDER, 0755, true);
43
        }
44
45
        // dump content in file
46
        ob_start();
47
        echo self::LINE;
48
        echo "File: {$headline1}\n";
49
        echo "Func: {$headline2}\n";
50
        echo "Date: {$dateTime}\n";
51
        echo self::LINE;
52
        var_dump($var);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($var) looks like debug code. Are you sure you do not want to remove it?
Loading history...
53
        echo self::LINE;
54
        file_put_contents(self::FOLDER . $filename, ob_get_contents());
55
        ob_end_clean();
56
    }
57
}
58