Test Failed
Branch master (360153)
by
unknown
05:51
created

ReflectionTrait::getClassFromClassProperty()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
crap 12
1
<?php
2
namespace Pbxg33k\Traits;
3
4
/**
5
 * Class ReflectionTrait
6
 *
7
 * This trait adds methods to retrieve properties easily using PHP Reflection
8
 *
9
 * @author  Oguzhan Uysal <[email protected]>
10
 * @package Pbxg33k\Traits
11
 */
12
trait ReflectionTrait
13
{
14
    /**
15
     * Tries to get the correct class name from the given docBlock for Reflection
16
     *
17
     * @param string $comment the docblock
18
     * @param bool $includeNamespaces
19
     * @param null|\ReflectionClass $reflectionClass
20
     *
21
     * @return bool|string
22
     */
23
    public static function getClassFromDocComment($comment, $includeNamespaces = true, $reflectionClass = null)
24
    {
25
        if (preg_match('~\@var[\s]+([A-Za-z0-9\\\\]+)~', $comment, $matches)) {
26
            if ($includeNamespaces) {
27
                if ($reflectionClass instanceof \ReflectionClass && !in_array($matches[1], HydratableTrait::$nonObjectTypes)) {
28
                    return ($reflectionClass->getNamespaceName()) ? sprintf('\%s\%s', $reflectionClass->getNamespaceName(), $matches[1]) :  sprintf('\%s', $matches[1]);
29
                }
30
                return $matches[1];
31
            }
32
            return join('', array_slice(explode('\\', $matches[1]), -1));
33
        }
34
35
        return false;
36
    }
37
}