Completed
Push — master ( 348a0e...d82154 )
by Maik
06:35
created

OrmClassUtil::getClassProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace Nkey\Caribu\Orm;
3
4
trait OrmClassUtil
5
{
6
7
    /**
8
     * Retrieve the properties from class
9
     *
10
     * @param string $class
11
     *            The name of class to get properties of
12
     *            
13
     * @return \ReflectionProperty[] Array of Reflection properties
14
     */
15 21
    private static function getClassProperties(string $class): array
16
    {
17 21
        $rf = new \ReflectionClass($class);
18
        
19 21
        return $rf->getProperties();
20
    }
21
22
    /**
23
     * Checks whether a type is an internal class defined by core or any extension
24
     *
25
     * @param string $type
26
     *            The type (class name) to check
27
     *            
28
     * @return bool
29
     */
30 14
    private static function isInternalClass(string $type): bool
31
    {
32
        try {
33 14
            $rf = new \ReflectionClass($type);
34 14
            return $rf->isInternal();
35
        } catch (\ReflectionException $exception) {
36
            // we do nothing and assume that the class is not checkable
37
        }
38
        return false;
39
    }
40
41
    /**
42
     * Build a full qualified class name including namespace
43
     *
44
     * @param string $ns
45
     *            The namespace of class
46
     * @param string $class
47
     *            The name of class
48
     *            
49
     * @return string The full qualified class name
50
     */
51 26
    private static function fullQualifiedName(string $ns, string $class): string
52
    {
53 26
        if (! class_exists($class)) {
54 4
            $class = sprintf("\\%s\\%s", $ns, $class);
55
        }
56 26
        return $class;
57
    }
58
}