Completed
Pull Request — master (#191)
by Serhii
02:32
created

HistoryRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 34.38 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 11
loc 32
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findAllHistory() 0 12 1
A getCount() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\History;
6
use Doctrine\Common\Persistence\ManagerRegistry;
7
8
class HistoryRepository extends AbstractRepository
9
{
10 6
    public function __construct(ManagerRegistry $registry)
11
    {
12 6
        parent::__construct($registry, History::class);
13 6
    }
14
15 1
    public function findAllHistory($limit, $page)
16
    {
17 1
        $qb = $this->createQueryBuilder('u')
18 1
            ->setMaxResults($limit)
19 1
            ->setFirstResult($page)
20 1
            ->orderBy('u.dateTime', 'DESC')
21
        ;
22
23 1
        $query = $qb->getQuery()->enableResultCache(self::CACHE_TTL);
24
25 1
        return $query->execute();
26
    }
27
28 1 View Code Duplication
    public function getCount()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30 1
        $qb = $this->createQueryBuilder('u');
31 1
        $qb->select($qb->expr()->count('u'));
32
33 1
        $query = $qb->getQuery();
34
35 1
        $query->useResultCache(true, 3600);
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\ORM\AbstractQuery::useResultCache() has been deprecated with message: 2.7 Use {@see enableResultCache} and {@see disableResultCache} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
36
37 1
        return $query->getSingleScalarResult();
38
    }
39
}
40