GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0a6f96...b0c756 )
by Ross
12s queued 10s
created

EntitySaver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A saveAll() 0 11 3
A removeAll() 0 7 2
A remove() 0 3 1
A __construct() 0 4 1
A save() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Savers;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\PrimaryKey\IdFieldInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
8
9
/**
10
 * Class EntitySaver
11
 *
12
 * Generic Entity Saver
13
 *
14
 * Can be used to save any entities as required
15
 *
16
 * For Entity specific saving logic, you should create an Entity Specific Saver
17
 * that subclasses:
18
 * \EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\AbstractEntitySpecificSaver
19
 *
20
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Savers
21
 */
22
class EntitySaver implements EntitySaverInterface
23
{
24
    /**
25
     * @var EntityManagerInterface
26
     */
27
    protected $entityManager;
28
29
    /**
30
     * @var string
31
     */
32
    protected $entityFqn;
33
34
    /**
35
     * AbstractSaver constructor.
36
     *
37
     * @param EntityManagerInterface $entityManager
38
     */
39
    public function __construct(
40
        EntityManagerInterface $entityManager
41
    ) {
42
        $this->entityManager = $entityManager;
43
    }
44
45
    /**
46
     * @param IdFieldInterface $entity
47
     *
48
     * @throws DoctrineStaticMetaException
49
     * @throws \ReflectionException
50
     */
51
    public function save(IdFieldInterface $entity): void
52
    {
53
        $this->saveAll([$entity]);
54
    }
55
56
    /**
57
     *
58
     *
59
     * @param array|IdFieldInterface[] $entities *
60
     */
61
    public function saveAll(array $entities): void
62
    {
63
        if (empty($entities)) {
64
            return;
65
        }
66
67
        foreach ($entities as $entity) {
68
            $this->entityManager->persist($entity);
69
        }
70
71
        $this->entityManager->flush();
72
    }
73
74
    /**
75
     * @param IdFieldInterface $entity
76
     *
77
     */
78
    public function remove(IdFieldInterface $entity): void
79
    {
80
        $this->removeAll([$entity]);
81
    }
82
83
    /**
84
     * @param array|IdFieldInterface[] $entities
85
     *
86
     */
87
    public function removeAll(array $entities): void
88
    {
89
        foreach ($entities as $entity) {
90
            $this->entityManager->remove($entity);
91
        }
92
93
        $this->entityManager->flush();
94
    }
95
}
96