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

DebugHelper::getBacktrace()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.0073

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 4
nop 0
dl 0
loc 27
ccs 14
cts 15
cp 0.9333
crap 5.0073
rs 8.439
c 0
b 0
f 0
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