Completed
Pull Request — master (#725)
by
unknown
01:55
created

RepositoryTrait::createNativeNamedQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Doctrine Bundle
5
 *
6
 * The code was originally distributed inside the Symfony framework.
7
 *
8
 * (c) Fabien Potencier <[email protected]>
9
 * (c) Doctrine Project, Benjamin Eberlei <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Doctrine\Bundle\DoctrineBundle\Repository;
16
17
use Doctrine\Common\Collections\Criteria;
18
use Doctrine\ORM\EntityManagerInterface;
19
use Doctrine\ORM\EntityRepository;
20
use Doctrine\ORM\NativeQuery;
21
use Doctrine\ORM\Query;
22
use Doctrine\ORM\Query\ResultSetMappingBuilder;
23
use Doctrine\ORM\QueryBuilder;
24
25
/**
26
 * A helpful trait when creating your own repository.
27
 *
28
 * @author Ryan Weaver <[email protected]>
29
 */
30
trait RepositoryTrait
31
{
32
    /**
33
     * @return EntityManagerInterface
34
     */
35
    abstract protected function getEntityManager();
36
37
    /**
38
     * @return string The class name for your entity.
39
     */
40
    abstract protected function getClassName();
41
42
    /**
43
     * @see EntityRepository::createQueryBuilder()
44
     *
45
     * @param string $alias
46
     * @param string $indexBy The index for the from.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $indexBy not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
47
     *
48
     * @return QueryBuilder
49
     */
50
    public function createQueryBuilder($alias, $indexBy = null)
51
    {
52
        return $this->getRepository()->createQueryBuilder($alias, $indexBy);
53
    }
54
55
    /**
56
     * @see EntityRepository::createResultSetMappingBuilder()
57
     *
58
     * @param string $alias
59
     *
60
     * @return ResultSetMappingBuilder
61
     */
62
    public function createResultSetMappingBuilder($alias)
63
    {
64
        return $this->getRepository()->createResultSetMappingBuilder($alias);
65
    }
66
67
    /**
68
     * @see EntityRepository::createNamedQuery()
69
     *
70
     * @param string $queryName
71
     *
72
     * @return Query
73
     */
74
    public function createNamedQuery($queryName)
75
    {
76
        return $this->getRepository()->createNamedQuery($queryName);
77
    }
78
79
    /**
80
     * @see EntityRepository::createNativeNamedQuery()
81
     *
82
     * @param string $queryName
83
     *
84
     * @return NativeQuery
85
     */
86
    public function createNativeNamedQuery($queryName)
87
    {
88
        return $this->getRepository()->createNativeNamedQuery($queryName);
89
    }
90
91
    /**
92
     * @see EntityRepository::clear()
93
     *
94
     * @return void
95
     */
96
    public function clear()
97
    {
98
        $this->getRepository()->clear();
99
    }
100
101
    /**
102
     * @see EntityRepository::find()
103
     *
104
     * @param mixed    $id          The identifier.
105
     * @param int|null $lockMode    One of the \Doctrine\DBAL\LockMode::* constants
106
     *                              or NULL if no specific lock mode should be used
107
     *                              during the search.
108
     * @param int|null $lockVersion The lock version.
109
     *
110
     * @return object|null The entity instance or NULL if the entity can not be found.
111
     */
112
    public function find($id, $lockMode = null, $lockVersion = null)
113
    {
114
        return $this->getRepository()->find($id, $lockMode, $lockVersion);
115
    }
116
117
    /**
118
     * @see EntityRepository::findAll()
119
     *
120
     * @return array The entities.
121
     */
122
    public function findAll()
123
    {
124
        return $this->getRepository()->findAll();
125
    }
126
127
    /**
128
     * @see EntityRepository::findBy()
129
     *
130
     * @param array      $criteria
131
     * @param array|null $orderBy
132
     * @param int|null   $limit
133
     * @param int|null   $offset
134
     *
135
     * @return array The objects.
136
     */
137
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
138
    {
139
        return $this->getRepository()->findBy($criteria, $orderBy, $limit, $offset);
140
    }
141
142
    /**
143
     * @see EntityRepository::findOneBy()
144
     *
145
     * @param array $criteria
146
     * @param array|null $orderBy
147
     *
148
     * @return object|null The entity instance or NULL if the entity can not be found.
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
149
     */
150
    public function findOneBy(array $criteria, array $orderBy = null)
151
    {
152
        return $this->findBy($criteria, $orderBy);
153
    }
154
155
    /**
156
     * @see EntityRepository::matching()
157
     *
158
     * @param \Doctrine\Common\Collections\Criteria $criteria
159
     *
160
     * @return \Doctrine\Common\Collections\Collection
161
     */
162
    public function matching(Criteria $criteria)
163
    {
164
        return $this->getRepository()->matching($criteria);
165
    }
166
167
    /**
168
     * @return EntityRepository
169
     */
170
    private function getRepository()
171
    {
172
        return $this->getEntityManager()->getRepository($this->getClassName());
173
    }
174
}
175