AbstractRepository::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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