Annotations   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAttributeType() 0 17 3
1
<?php
2
namespace Vsmoraes\DynamoMapper;
3
4
use Vsmoraes\DynamoMapper\Exception\AnnotationNotFound;
5
use Vsmoraes\DynamoMapper\Exception\InvalidAttributeType;
6
use ICanBoogie\Inflector;
7
8
class Annotations
9
{
10
    /**
11
     * @var \ReflectionClass
12
     */
13
    private $reflectionClass;
14
15
    public function __construct(\ReflectionClass $reflectionClass)
16
    {
17
        $this->reflectionClass = $reflectionClass;
18
    }
19
20
    /**
21
     * @param string $attribute
22
     * @return string
23
     * @throws AnnotationNotFound
24
     * @throws InvalidAttributeType
25
     */
26
    public function getAttributeType(string $attribute): string
27
    {
28
        $attribute = Inflector::get()->camelize($attribute, Inflector::DOWNCASE_FIRST_LETTER);
29
        $docblock = $this->reflectionClass->getProperty($attribute)
30
            ->getDocComment();
31
32
        $annotations = [];
33
        preg_match_all('/@var\s*([^\s]+)/i', $docblock, $annotations, PREG_SET_ORDER);
34
35
        if (empty($annotations) || ! isset($annotations[0][1])) {
36
            throw new AnnotationNotFound;
37
        }
38
39
        $type = strtolower($annotations[0][1]);
40
41
        return $type;
42
    }
43
}
44