Completed
Push — master ( 3e5311...09edda )
by Beniamin
05:08
created

TableRecognizer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 68.75%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 6
c 4
b 0
f 2
lcom 0
cbo 0
dl 0
loc 42
ccs 11
cts 16
cp 0.6875
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B recognizeType() 0 15 5
A extractClassName() 0 7 1
1
<?php
2
namespace Phuria\QueryBuilder;
3
4
/**
5
 * @author Beniamin Jonatan Šimko <[email protected]>
6
 */
7
class TableRecognizer
8
{
9
    const TYPE_CLOSURE = 1;
10
    const TYPE_ROUTE = 2;
11
    const TYPE_CLASS_NAME = 3;
12
    const TYPE_TABLE_NAME = 4;
13
    const TYPE_SUB_QUERY = 5;
14
15
    /**
16
     * @param mixed $stuff
17
     *
18
     * @return int
19
     */
20 24
    public function recognizeType($stuff)
21
    {
22 24
        switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($stuff, '\\') of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
23 24
            case $stuff instanceof \Closure:
24 1
                return static::TYPE_CLOSURE;
25 24
            case $stuff instanceof QueryBuilder:
26 2
                return static::TYPE_SUB_QUERY;
27 24
            case false !== strpos($stuff, '.'):
28 1
                return static::TYPE_ROUTE;
29 24
            case strpos($stuff, '\\'):
30 1
                return static::TYPE_CLASS_NAME;
31
        }
32
33 24
        return static::TYPE_TABLE_NAME;
34
    }
35
36
    /**
37
     * @param \Closure $closure
38
     *
39
     * @return string
40
     */
41
    public function extractClassName(\Closure $closure)
42
    {
43
        $ref = new \ReflectionFunction($closure);
44
        $firstParameter = $ref->getParameters()[0];
45
46
        return $firstParameter->getClass()->getName();
47
    }
48
}