Completed
Pull Request — newinternal (#285)
by Simon
06:16 queued 03:05
created

DebugHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 14
cts 17
cp 0.8235
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_debug_backtrace() 0 4 1
B getBacktrace() 0 27 5
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Helpers;
10
11
/**
12
 * DebugHelper provides backtrace utilities for debugging and error logging
13
 */
14
class DebugHelper
15
{
16
    /**
17
     * Internal mockable method wrapper for debug_backtrace.
18
     *
19
     * As mocking out debug_backtrace uses debug_backtrace internally, we need this in order to not cause a recursive
20
     * cascade until the runtime explodes.
21
     *
22
     * Instead, we mock this method, which allows debug_backtrace to still be called correctly.
23
     *
24
     * @return array
25
     */
26
    public function get_debug_backtrace()
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
27
    {
28
        return debug_backtrace();
29
    }
30
31
    /**
32
     * Returns a string representation of the current backtrace for display.
33
     *
34
     * Note that this explicitly excludes the top two frames, which will be methods from this class.
35
     *
36
     * @return string
37
     */
38 1
    public function getBacktrace()
39
    {
40 1
        $backtrace = $this->get_debug_backtrace();
41
42 1
        $output = "";
43
44 1
        $count = 0;
45 1
        foreach ($backtrace as $line) {
46 1
            if ($count <= 1) {
47 1
                $count++;
48 1
                continue;
49
            }
50
51 1
            $output .= "#{$count}: ";
52
53 1
            if (isset($line['type']) && $line['type'] != "") {
54
                $output .= $line['class'] . $line['type'];
55
            }
56
57 1
            $output .= $line['function'] . "(...)";
58 1
            $output .= " [{$line['file']}#{$line['line']}\r\n";
59
60 1
            $count++;
61
        }
62
63 1
        return $output;
64
    }
65
}
66