Test Setup Failed
Push — master ( d6bd2d...bc363c )
by Alexey
03:03
created

PostRepository::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
eloc 2
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
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
8
9
class PostRepository extends EntityRepository
10 1
{
11
    public function add(Post $entity)
12
    {
13 1
        $this->getEntityManager()->persist($entity);
14
    }
15 1
16 1
    public function getPostWithComments($postId)
17 1
    {
18 1
        /** @var QueryBuilder $qb */
19 1
        $qb = $this->createQueryBuilder('p');
20 1
        return $qb
21 1
            ->select(['p', 'c', 'a'])
22
            ->leftJoin('p.comments', 'c')
23
            ->leftJoin('c.author', 'a')
24
            ->where($qb->expr()->eq('p.id', ':post_id'))
25
            ->orderBy('c.number', 'asc')
26
            ->setParameter('post_id', $postId)
27
            ->getQuery()->getOneOrNullResult()
28
        ;
29
    }
30
}