BasePostRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findLastPostQueryBuilder() 0 6 1
A countCommentsQuery() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NewsBundle\Entity;
15
16
use Doctrine\ORM\EntityRepository;
17
use Doctrine\ORM\QueryBuilder;
18
use Sonata\NewsBundle\Model\CommentInterface;
19
20
class BasePostRepository extends EntityRepository
21
{
22
    /**
23
     * return last post query builder.
24
     *
25
     * @param int $limit
26
     *
27
     * @return \Doctrine\ORM\QueryBuilder
28
     */
29
    public function findLastPostQueryBuilder($limit)
0 ignored issues
show
Unused Code introduced by
The parameter $limit is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        return $this->createQueryBuilder('p')
32
            ->where('p.enabled = true')
33
            ->orderBy('p.createdAt', 'DESC');
34
    }
35
36
    /**
37
     * return count comments QueryBuilder.
38
     *
39
     * @param PostInterface $post
40
     *
41
     * @return QueryBuilder
42
     */
43
    public function countCommentsQuery($post)
44
    {
45
        $qb = $this->createQueryBuilder('c');
46
47
        return $qb
48
            ->select('COUNT(c.id)')
49
            ->where($qb->expr()->eq('c.status', ':status'))
50
            ->andWhere($qb->expr()->eq('c.post', ':post'))
51
            ->setParameters([
52
                'status' => CommentInterface::STATUS_VALID,
53
                'post' => $post,
54
            ]);
55
    }
56
}
57