Completed
Push — master ( 98a82f...7bd861 )
by Márcio Lucas R.
11s
created

Annotations::getAnnotation()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 1
1
<?php
2
3
/**
4
 * Copyright (c) 2017. Este código foi feito por @marciioluucas, sob licença MIT
5
 */
6
namespace Phiber\Util;
7
8
use Phiber\Util\FuncoesReflections;
9
10
/**
11
 * A classe Annotations é responsável por pegar por reflexão os comentários de mapeamento das classes.
12
 * 
13
 * @package util
14
 */
15
class Annotations 
16
{
17
    /**
18
     * Recupera os comentários de mapeamentos das classes de modelo.
19
     * 
20
     * @param $object
21
     * Retorna um array de atributos
22
     * @return array
23
     */
24
    final public static function getAnnotation($object)
25
    {
26
        $funReflec = new FuncoesReflections();
27
        
28
        $output = array();
29
        
30
        $pattern = '/@+_+[A-z]\w+=\w+/';
31
        
32
        $fullComments = $funReflec->retornaComentariosAtributos($object);
33
        $attribuites   = $funReflec->pegaAtributosDoObjeto($object);
34
        
35
        $annotationsList = [];
36
        
37
        $limit    = count($attribuites);
38
        $iterator = 0;
39
        for ($iterator; $iterator < $limit; $iterator++) {
40
            
41
            preg_match_all(
42
                $pattern,
43
                $fullComments[$attribuites[$iterator]],
44
                $output
45
            );
46
47
            $annotationsList[ $attribuites[$iterator] ] = $output[0];
48
        }
49
50
        return $annotationsList;
51
    }
52
}
53