Reflection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 3 Features 0
Metric Value
wmc 5
c 4
b 3
f 0
lcom 1
cbo 1
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getImplementedClassesAndInterfaces() 0 19 5
1
<?php
2
3
namespace PEIP\Util;
4
5
/*
6
 * To change this template, choose Tools | Templates
7
 * and open the template in the editor.
8
 */
9
10
/**
11
 * Description of Reflection.
12
 *
13
 * @author timo
14
 */
15
class Reflection
16
{
17
    protected static $classInfo = [];
18
19
    /*
20
     * returns implemeted interfaces and (parents) class names as array.
21
     * When second parameter ($store) ist set to FALSE, the class-info will
22
     * not be cached. This serves some memory (e.g. 500b per requested class),
23
     * but wil make subsequent calls slower (about 4-5 times). So when you use
24
     * this method only once per process, set $store to FALSE - otherwise set
25
     * $store to TRUE. Since PEIP is created for performance on heavy usage
26
     * the default for store is TRUE.
27
     *
28
     * @param  string name/instance of the class to return info for
29
     * @param  boolean wether to store the info for the class internally
30
     * @return array array with interface/class info for the class
31
     */
32
33
    public static function getImplementedClassesAndInterfaces($class, $store = true)
34
    {
35
        $class = is_object($class) ? get_class($class) : (string) $class;
36
        if (isset(self::$classInfo[$class])) {
37
            return self::$classInfo[$class];
38
        }
39
        $cls = ReflectionPool::getInstance($class);
40
        // get the names of implemented interfaces
41
        $classInfo = (array) $cls->getInterfaceNames();
42
        $classInfo[] = $cls->getName();
43
        // get names of parent-classes
44
        while ($cls = $cls->getParentClass()) {
45
            $classInfo[] = $cls->getName();
46
        }
47
48
        return $store
49
            ? self::$classInfo[$class] = $classInfo
50
            : $classInfo;
51
    }
52
}
53