ObjectUtils::getConstants()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 1
1
<?php
2
namespace Bedd\Common;
3
4
use Bedd\Common\Traits\StaticClassTrait;
5
6
/**
7
 * ObjectUtils
8
 */
9
class ObjectUtils
10
{
11
    use StaticClassTrait;
12
13
    /**
14
     * Get all constants of the given $class or object.
15
     * Constant name in key, constant value in value.
16
     *
17
     * @param object|string $class
18
     * @return array
19
     */
20
    public static function getConstants($class)
21
    {
22
        static $constants = [];
23
        if (is_object($class)) {
24
            $class = get_class($class);
25
        }
26
        if (!isset($constants[$class])) {
27
            $constants[$class] = (new \ReflectionClass($class))->getConstants();
28
        }
29
        return $constants[$class];
30
    }
31
}
32