Debug   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 48
ccs 11
cts 15
cp 0.7332
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getScope() 0 4 1
A enterScope() 0 9 2
A exitScope() 0 8 2
1
<?php
2
3
namespace Zicht\Tool;
4
5
/**
6
 * Debug helper class
7
 */
8
final class Debug
9
{
10
    /**
11
     * @var array
12
     */
13
    public static $scope = array();
14
15
    public static $scopeChange = array();
16
17
    /**
18
     * @return mixed
19
     */
20
    public static function getScope()
21
    {
22
        return self::$scope[count(self::$scope) - 1];
23
    }
24
25
    /**
26
     * Keeps track of scope
27
     *
28
     * @param string $scope
29
     * @return void
30
     */
31 8
    public static function enterScope($scope)
32
    {
33 8
        if (!is_scalar($scope)) {
34
            throw new \InvalidArgumentException("Only scalars allowed as scope identifiers");
35
        }
36 8
        array_push(self::$scope, $scope);
37 8
        list($call) = debug_backtrace(0);
38 8
        array_push(self::$scopeChange, $call);
39 8
    }
40
41
42
    /**
43
     * @param string $scope
44
     * @throws ScopeException
45
     * @return void
46
     */
47 8
    public static function exitScope($scope)
48
    {
49 8
        $current = array_pop(self::$scope);
50 8
        $call = array_pop(self::$scopeChange);
51 8
        if ($scope !== $current) {
52
            throw new \LogicException("The current scope '$current' was not closed properly, while trying to close '$scope', which was opened at {$call['file']}@{$call['line']}");
53
        }
54 8
    }
55
}
56