Completed
Push — master ( efc7f4...497618 )
by Filipe
02:47
created

RelationsUtilityMethods::getParentEntityMapper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/orm package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Orm\Mapper\Relation;
11
12
use Slick\Orm\Descriptor\EntityDescriptorInterface;
13
use Slick\Orm\Descriptor\Field\FieldDescriptor;
14
use Slick\Orm\Descriptor\Field\FieldsCollection;
15
use Slick\Orm\Orm;
16
17
/**
18
 * Useful methods for relations
19
 *
20
 * @package Slick\Orm\Mapper\Relation
21
 * @author  Filipe Silva <[email protected]>
22
 */
23
trait RelationsUtilityMethods
24
{
25
26
    /**
27
     * Gets the parent or related entity descriptor
28
     *
29
     * @return EntityDescriptorInterface
30
     */
31
    abstract public function getParentEntityDescriptor();
32
33
    /**
34
     * Gets parent entity class name
35
     *
36
     * @return string
37
     */
38
    abstract public function getParentEntity();
39
40
    /**
41
     * Gets the parent entity primary key field name
42
     *
43
     * @return string
44
     */
45 4
    public function getParentPrimaryKey()
46
    {
47 4
        return $this->getParentEntityDescriptor()
48 4
            ->getPrimaryKey()
49 4
            ->getField();
50
    }
51
52
    /**
53
     * Gets parent entity repository
54
     *
55
     * @return \Slick\Orm\Repository\EntityRepository
56
     */
57 2
    public function getParentRepository()
58
    {
59 2
        return Orm::getRepository($this->getParentEntity());
60
    }
61
62
    /**
63
     * Gets the entity mapper of parent entity repository
64
     *
65
     * @return \Slick\Orm\EntityMapperInterface
66
     */
67 2
    public function getParentEntityMapper()
68
    {
69 2
        return $this->getParentRepository()
70 2
            ->getEntityMapper();
71
    }
72
73
    /**
74
     * Gets parent entity table name
75
     *
76
     * @return string
77
     */
78 4
    public function getParentTableName()
79
    {
80 4
        return $this->getParentEntityDescriptor()
81 4
            ->getTableName();
82
    }
83
84
    /**
85
     * Get parent entity fields collection
86
     *
87
     * @return FieldsCollection|FieldDescriptor[]
88
     */
89 2
    public function getParentFields()
90
    {
91 2
        return $this->getParentEntityDescriptor()
92 2
            ->getFields();
93
    }
94
}