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

PostRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 2
c 2
b 1
f 1
lcom 0
cbo 4
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A getPostWithComments() 0 14 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
}