Caller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A guess() 0 12 3
A shouldIgnore() 0 4 2
1
<?php
2
3
namespace Vehikl\Flip;
4
5
class Caller
6
{
7
    /**
8
     * Guess and return the object a feature is mixed into
9
     *
10
     * @throws \LogicException
11
     * @return object
12
     */
13 8
    public static function guess()
14
    {
15 8
        foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 10) as $trace) {
16 6
            if (self::shouldIgnore($trace['object'] ?? null)) {
17 6
                continue;
18
            }
19
20 6
            return $trace['object'];
21
        }
22
23 2
        throw new \LogicException('No caller found.');
24
    }
25
26
    /**
27
     * Determine if the guesser should ignore the passed object from the
28
     * stack trace.
29
     *
30
     * @param $object
31
     *
32
     * @return bool
33
     */
34 6
    private static function shouldIgnore($object)
35
    {
36 6
        return $object == null || $object instanceof Feature;
37
    }
38
}
39