Completed
Pull Request — master (#142)
by Ihor
14:50
created

AbstractRepository::save()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 12
1
<?php
2
3
namespace AppBundle\Repository;
4
5
use AppBundle\Exception\DuplicateException;
6
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
7
use Doctrine\ORM\EntityRepository;
8
9 4
abstract class AbstractRepository extends EntityRepository implements BasicRepositoryInterface
10
{
11 4 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...
12 4
    {
13
        $qb = $this->createQueryBuilder('u');
14 4
        $query = $qb->select($qb->expr()->count('u'))->getQuery();
15
16
        return $query->getSingleScalarResult();
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
22
     */
23
    public function save($entity, $doFlush = true)
24
    {
25
        try {
26
            $this->getEntityManager()->persist($entity);
27
            if ($doFlush) {
28
                $this->getEntityManager()->flush();
29
            }
30
        } catch (UniqueConstraintViolationException $e) {
31
            throw new DuplicateException('Entity has duplicate by one of unique field');
32
        }
33
    }
34
}
35