BlogBundle/Entity/Repository/PostRepository.php
public function countTotal($categoryId=null)
    {
        $qb = $this->getQueryBuilder()
            ->select('COUNT(p)');

        if(!is_null($categoryId)){
            $qb->join('p.categories', 'c')
               ->where('c.id = :categoryId')
               ->setParameter('categoryId', $categoryId);
        }
        
        return $qb->getQuery()->getSingleScalarResult();
    }
public function countTotal($categoryId=null)
    {
        $qb = $this->getQueryBuilder()
            ->select('COUNT(p)');

        if(!is_null($categoryId)){
            $qb->join('p.categories', 'c')
               ->where('c.id = :categoryId')
               ->setParameter('categoryId', $categoryId);
        }
        
        return $qb->getQuery()->getSingleScalarResult();
    }
Count the total of rows

@return int