Passed
Push — master ( 107afa...98b7dd )
by Jean
02:12
created

UsageException::rewindStackWhile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
namespace JClaveau\Exceptions;
3
4
/**
5
 */
6
class UsageException extends \Exception
7
{
8
    /**
9
     * /
10
    public function new_($message)
11
    {
12
        return new static($message);
13
    }
14
15
    /**
16
     */
17
    public function __construct()
18
    {
19
        parent::__construct(...func_get_args());
0 ignored issues
show
Bug introduced by
func_get_args() is expanded, but the parameter $message of Exception::__construct() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        parent::__construct(/** @scrutinizer ignore-type */ ...func_get_args());
Loading history...
20
21
        $this->rewindStackWhile( function($backtrace, $level) {
22
            // Finds the closest caller
23
            return  isset($backtrace[ $level ]['class'])
24
                &&  $backtrace[ $level ]['class'] == __CLASS__;
25
        }, 0 );
26
    }
27
28
    /**
29
     */
30
    protected function rewindStackWhile(callable $scope_checker, $stack_max_depth=20)
31
    {
32
        $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, $stack_max_depth);
33
        $i         = 1;
34
        $caller    = $backtrace[$i];
35
        while ( $scope_checker( $backtrace, $i ) ) {
36
            $i++;
37
            $caller = $backtrace[$i];
38
            // TODO remove the prevuce levels of the stack?
39
        }
40
41
        // var_export($backtrace);
42
        // var_export($caller);
43
44
        $this->file = $caller['file'];
45
        $this->line = $caller['line'];
46
47
        // var_export($this->stack);
48
    }
49
50
    /**/
51
}
52