AbstractRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A persist() 0 4 1
A flush() 0 4 1
A save() 0 5 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Loevgaard\DandomainStock\Repository;
6
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Common\Persistence\ManagerRegistry;
9
use Loevgaard\DandomainStock\Repository\Generated\AbstractRepositoryTrait;
10
11
abstract class AbstractRepository extends ServiceEntityRepository
12
{
13
    use AbstractRepositoryTrait;
14
15
    public function __construct(ManagerRegistry $registry, string $entityClass)
16
    {
17
        parent::__construct($registry, $entityClass);
18
    }
19
20
    /**
21
     * @param $object
22
     * @throws \Doctrine\ORM\ORMException
23
     */
24
    public function persist($object) : void
25
    {
26
        $this->getEntityManager()->persist($object);
27
    }
28
29
    /**
30
     * @param null|object|array $entity
31
     * @throws \Doctrine\ORM\ORMException
32
     * @throws \Doctrine\ORM\OptimisticLockException
33
     */
34
    public function flush($entity = null) : void
35
    {
36
        $this->getEntityManager()->flush($entity);
37
    }
38
39
    /**
40
     * Helper method for calling persist and flush successively
41
     *
42
     * @param object $entity
43
     * @throws \Doctrine\ORM\ORMException
44
     * @throws \Doctrine\ORM\OptimisticLockException
45
     */
46
    public function save($entity)
47
    {
48
        $this->persist($entity);
49
        $this->flush();
50
    }
51
}
52