Reflect   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilename() 0 12 2
A getDirectory() 0 8 2
A getNamespace() 0 14 3
A getParameters() 0 18 3
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) {
20
            // Ignore
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) {
44
            // Ignore
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) {
61
            // Ignore
62
        }
63
64
        return $params;
65
    }
66
67
}
68