Completed
Push — master ( 5aaba6...c938da )
by Changwan
04:09
created

BelongsTo   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRelation() 0 6 1
1
<?php
2
namespace Wandu\Database\Annotations;
3
4
use Doctrine\Common\Annotations\Annotation\Required;
5
use Doctrine\Common\Annotations\Annotation\Target;
6
use Wandu\Database\DatabaseManager;
7
use Wandu\Database\Query\SelectQuery;
8
9
/**
10
 * @Annotation
11
 * @Target({"PROPERTY"})
12
 */
13
class BelongsTo implements RelationInterface
14
{
15
    /**
16
     * @Required
17
     * @var string
18
     */
19
    public $related;
20
21
    /**
22
     * @var string
23
     */
24
    public $key = 'id';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getRelation(DatabaseManager $manager, $columnValue)
30
    {
31 3
        return $manager->repository($this->related)->first(function (SelectQuery $query) use ($columnValue) {
32 3
            return $query->where($this->key, $columnValue);
33 3
        });
34
    }
35
}
36