Completed
Push — master ( 1cbd4f...6f70d1 )
by Beniamin
07:58
created

TableRecognizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 64.29%

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 5
c 5
b 0
f 3
lcom 0
cbo 0
dl 0
loc 39
ccs 9
cts 14
cp 0.6429
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A recognizeType() 0 13 4
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_CLASS_NAME = 2;
11
    const TYPE_TABLE_NAME = 3;
12
    const TYPE_SUB_QUERY = 4;
13
14
    /**
15
     * @param mixed $stuff
16
     *
17
     * @return int
18
     */
19 25
    public function recognizeType($stuff)
20
    {
21 25
        switch (true) {
22 25
            case $stuff instanceof \Closure:
23 1
                return static::TYPE_CLOSURE;
24 25
            case $stuff instanceof QueryBuilder:
25 2
                return static::TYPE_SUB_QUERY;
26 25
            case false !== strpos($stuff, '\\'):
27 1
                return static::TYPE_CLASS_NAME;
28
        }
29
30 25
        return static::TYPE_TABLE_NAME;
31
    }
32
33
    /**
34
     * @param \Closure $closure
35
     *
36
     * @return string
37
     */
38
    public function extractClassName(\Closure $closure)
39
    {
40
        $ref = new \ReflectionFunction($closure);
41
        $firstParameter = $ref->getParameters()[0];
42
43
        return $firstParameter->getClass()->getName();
44
    }
45
}