Completed
Push — master ( 5c0675...554793 )
by Helmut
03:37
created

Reflect::getFilename()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 5
nc 3
nop 1
1
<?php 
2
3
namespace Helmut\Forms\Utility;
4
5
use ReflectionClass;
6
use ReflectionMethod;
7
use ReflectionException;
8
9
class Reflect {
10
	
11
    public static function getFilename($class) 
12
    {
13
        try {
14
           
15
            $reflector = new ReflectionClass($class);
16
17
            return $reflector->getFileName();
18
19
        } catch (ReflectionException $ex) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
20
21
        }
22
    }
23
24
    public static function getDirectory($class) 
25
    {
26
        $filename = static::getFilename($class);
27
28
        if ( ! is_null($filename)) {
29
            return dirname($filename);
30
        }
31
    }    
32
33
    public static function getNamespace($class) 
34
    {
35
        try {
36
37
            $reflector = new ReflectionClass($class);
38
39
            if ($reflector->inNamespace()) {
40
                return $reflector->getNamespaceName();
41
            }
42
43
        } catch (ReflectionException $ex) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
44
45
        }            
46
    }
47
48
    public static function getParameters($class, $method)
49
    {
50
        $params = [];
51
52
        try {
53
54
            $method = new ReflectionMethod($class, $method);
55
56
            foreach($method->getParameters() as $param) {
57
                $params[] = $param->getName();
58
            }
59
60
        } catch (ReflectionException $ex) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
61
62
        }
63
64
        return $params;
65
    }
66
67
}
68