Passed
Push — master ( a70199...a4ba76 )
by Beniamin
03:44
created

TableRecognizer::extractClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\SQLBuilder;
13
14
use Phuria\SQLBuilder\QueryBuilder\AbstractBuilder;
15
16
/**
17
 * @author Beniamin Jonatan Šimko <[email protected]>
18
 */
19
class TableRecognizer
20
{
21
    const TYPE_CLOSURE = 1;
22
    const TYPE_CLASS_NAME = 2;
23
    const TYPE_TABLE_NAME = 3;
24
    const TYPE_SUB_QUERY = 4;
25
26
    /**
27
     * @param mixed $stuff
28
     *
29
     * @return int
30
     */
31 1
    public function recognizeType($stuff)
32
    {
33 1
        switch (true) {
34 1
            case $stuff instanceof \Closure:
35 1
                return static::TYPE_CLOSURE;
36 1
            case $stuff instanceof AbstractBuilder:
37 1
                return static::TYPE_SUB_QUERY;
38 1
            case false !== strpos($stuff, '\\'):
39 1
                return static::TYPE_CLASS_NAME;
40
        }
41
42 1
        return static::TYPE_TABLE_NAME;
43
    }
44
45
    /**
46
     * @param \Closure $closure
47
     *
48
     * @return string
49
     */
50 1
    public function extractClassName(\Closure $closure)
51
    {
52 1
        $ref = new \ReflectionFunction($closure);
53 1
        $firstParameter = $ref->getParameters()[0];
54
55 1
        return $firstParameter->getClass()->getName();
56
    }
57
}