Passed
Push — feature/0.7.0 ( 0c7d59...ae5b22 )
by Ryuichi
78:01 queued 33:04
created

QueryExtendReader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotationInfo() 0 3 1
B read() 0 22 5
1
<?php
2
namespace WebStream\Annotation\Reader\Extend;
3
4
use WebStream\Container\Container;
5
6
/**
7
 * QueryExtendReader
8
 * @author Ryuichi Tanaka
9
 * @since 2017/01/16
10
 * @version 0.7
11
 */
12
class QueryExtendReader extends ExtendReader
13
{
14
    /**
15
     * @var array<Container> アノテーション情報リスト
16
     */
17
    private $annotationInfo;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function getAnnotationInfo()
23
    {
24
        return $this->annotationInfo;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function read(array $annotationInfoList)
31
    {
32
        $func = function ($queryKey, $xpath) use ($annotationInfoList) {
33
            $query = null;
34
            foreach ($annotationInfoList as $annotationInfo) {
35
                $xmlObjects = $annotationInfo[$queryKey];
36
                foreach ($xmlObjects as $xmlObject) {
37
                    $xmlElement = $xmlObject->xpath($xpath);
38
                    if (!empty($xmlElement)) {
39
                        $query = ["sql" => trim($xmlElement[0]->__toString()), "method" => $xmlElement[0]->getName()];
40
                        $entity = $xmlElement[0]->attributes()["entity"];
41
                        $query["entity"] = $entity !== null ? $entity->__toString() : null;
42
                        break;
43
                    }
44
                }
45
            }
46
47
            return $query;
48
        };
49
50
        $this->annotationInfo = function ($queryKey, $xpath) use ($func) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type WebStream\Container\Container[] of property $annotationInfo.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
            return $func($queryKey, $xpath);
52
        };
53
    }
54
}
55