ReflectionTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 26
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getClassFromDocComment() 0 14 6
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
}