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

BelongsTo::getRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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