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
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