Passed
Push — master ( 88105a...84be9d )
by Alexey
17:21
created

PostRepository::getPostWithComments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 2
b 1
f 1
cc 1
eloc 10
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\QueryBuilder;
7
8
class PostRepository extends EntityRepository
9
{
10 1
    public function getPostWithComments($postId)
11
    {
12
        /** @var QueryBuilder $qb */
13 1
        $qb = $this->createQueryBuilder('p');
14
        return $qb
15 1
            ->select(['p', 'c', 'a'])
16 1
            ->leftJoin('p.comments', 'c')
17 1
            ->leftJoin('c.author', 'a')
18 1
            ->where($qb->expr()->eq('p.id', ':post_id'))
19 1
            ->orderBy('c.number', 'asc')
20 1
            ->setParameter('post_id', $postId)
21 1
            ->getQuery()->getOneOrNullResult()
22
        ;
23
    }
24
}