Completed
Push — develop ( c0e59c...ad429f )
by Marek
02:45
created

AbstractEntityRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A persist() 0 11 2
1
<?php
2
namespace AppBundle\Entity\Repository;
3
4
use AppBundle\Entity\AbstractEntity;
5
use Doctrine\ORM\EntityRepository;
6
7
abstract class AbstractEntityRepository extends EntityRepository
8
{
9
    /**
10
     * Persist and flush entity
11
     *
12
     * @param AbstractEntity $entity
13
     */
14
    public function persist(AbstractEntity $entity)
15
    {
16
        $entityClass = get_class($entity);
17
        if ($this->getEntityName() !== $entity) {
18
            $msg = sprintf('Entity "%s" does not belong to this repository', $entityClass);
19
            throw new \InvalidArgumentException($msg);
20
        }
21
22
        $this->_em->persist($entity);
23
        $this->_em->flush($entity);
24
    }
25
}
26