Passed
Push — 0.x ( 59f0c9...e3354a )
by Pavel
03:50
created

IndexRepository   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findByVacancyId() 0 19 1
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\SanityBundle\Entity\Repository\Vacancy;
17
18
use Doctrine\ORM\Cache;
19
use Veslo\AppBundle\Entity\Repository\BaseEntityRepository;
20
use Veslo\SanityBundle\Entity\Vacancy\Index;
21
22
/**
23
 * Sanity index repository
24
 */
25
class IndexRepository extends BaseEntityRepository
26
{
27
    /**
28
     * Returns a sanity index instance with all related data for the specified vacancy identifier
29
     *
30
     * @param int $vacancyId Vacancy identifier
31
     *
32
     * @return Index|null
33
     */
34
    public function findByVacancyId(int $vacancyId): ?Index
35
    {
36
        $queryBuilder = $this->createQueryBuilder('e');
37
        $queryBuilder
38
            // fetch join for caching.
39
            ->leftJoin('e.tags', 't')
40
            ->addSelect('t')
41
            ->andWhere($queryBuilder->expr()->eq('e.vacancyId', ':vacancyId'))
42
            ->setParameter('vacancyId', $vacancyId)
43
        ;
44
45
        $query = $queryBuilder->getQuery();
46
        $query
47
            ->setCacheable(true)
48
            ->setCacheMode(Cache::MODE_NORMAL)
49
            ->useResultCache(true)
50
        ;
51
52
        return $query->getOneOrNullResult();
53
    }
54
}
55