PhpunitFatalErrorHandling   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateCallTrace() 0 19 3
A setupErrorHandling() 0 6 1
1
<?php
2
3
namespace Yoghi\Bundle\MaddaBundleTest\Utils;
4
5
trait PhpunitFatalErrorHandling
6
{
7
    public static function generateCallTrace($exception = null)
8
    {
9
        if (is_null($exception)) {
10
            $exception = new Exception();
11
        }
12
        $trace = explode("\n", $exception->getTraceAsString());
13
        // reverse array to make steps line up chronologically
14
        // // $trace = array_reverse($trace);
15
        array_shift($trace); // remove {main}
16
        array_pop($trace); // remove call to this method
17
        $length = count($trace);
18
        $result = [];
19
20
        for ($i = 0; $i < $length; ++$i) {
21
            $result[] = ($i + 1).')'.substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering
22
        }
23
24
        return "\t".implode("\n\t", $result);
25
    }
26
27
    /**
28
     * @beforeClass
29
     */
30
    public static function setupErrorHandling()
31
    {
32
        set_exception_handler(function($exception) {
33
            self::generateCallTrace($exception);
34
        });
35
    }
36
}
37