Passed
Pull Request — master (#125)
by David
03:21
created

ForeignKeyAnalyzerTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotations() 0 11 3
A getLocalColumns() 0 8 2
1
<?php
2
3
4
namespace TheCodingMachine\TDBM\Utils;
5
6
7
use Doctrine\DBAL\Schema\Column;
8
use TheCodingMachine\TDBM\Utils\Annotation\Annotations;
9
10
trait ForeignKeyAnalyzerTrait
11
{
12
    /**
13
     * @var Annotations[]
14
     */
15
    private $annotations;
16
    /**
17
     * @var Column[]
18
     */
19
    private $localColumns;
20
21
    /**
22
     * @return Column[]
23
     */
24
    private function getLocalColumns(): array
25
    {
26
        if ($this->localColumns === null) {
27
            $localColumnNames = $this->foreignKey->getUnquotedLocalColumns();
28
29
            $this->localColumns = array_map([$this->foreignKey->getLocalTable(), 'getColumn'], $localColumnNames);
30
        }
31
        return $this->localColumns;
32
    }
33
34
    /**
35
     * @return Annotations[]
36
     */
37
    private function getAnnotations(): array
38
    {
39
        if ($this->annotations === null) {
40
            $this->annotations = [];
41
42
            // Are all columns nullable?
43
            foreach ($this->getLocalColumns() as $column) {
44
                $this->annotations[] = $this->annotationParser->getColumnAnnotations($column, $this->foreignKey->getLocalTable());
0 ignored issues
show
Bug introduced by
The property annotationParser does not exist on TheCodingMachine\TDBM\Ut...ForeignKeyAnalyzerTrait. Did you mean annotations?
Loading history...
45
            }
46
        }
47
        return $this->annotations;
48
    }
49
}
50