Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
ConformiteOrganisationSubscriber | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSubscribedEvents | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
prePersist | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
preUpdate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
processConformiteOrganisation | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace App\Domain\Registry\Symfony\EventSubscriber\Doctrine; |
6 | |
7 | use App\Domain\Registry\Calculator\ConformiteOrganisationConformiteCalculator; |
8 | use App\Domain\Registry\Model\ConformiteOrganisation\Evaluation; |
9 | use Doctrine\Common\EventSubscriber; |
10 | use Doctrine\ORM\Event\PrePersistEventArgs; |
11 | use Doctrine\ORM\Event\PreUpdateEventArgs; |
12 | |
13 | class ConformiteOrganisationSubscriber implements EventSubscriber |
14 | { |
15 | /** |
16 | * @var ConformiteOrganisationConformiteCalculator |
17 | */ |
18 | private $conformiteCalculator; |
19 | |
20 | public function __construct(ConformiteOrganisationConformiteCalculator $calculator) |
21 | { |
22 | $this->conformiteCalculator = $calculator; |
23 | } |
24 | |
25 | public function getSubscribedEvents(): array |
26 | { |
27 | return [ |
28 | 'prePersist', |
29 | 'preUpdate', |
30 | ]; |
31 | } |
32 | |
33 | public function prePersist(PrePersistEventArgs $args) |
34 | { |
35 | $this->processConformiteOrganisation($args); |
36 | } |
37 | |
38 | public function preUpdate(PreUpdateEventArgs $args) |
39 | { |
40 | $this->processConformiteOrganisation($args); |
41 | } |
42 | |
43 | private function processConformiteOrganisation(PrePersistEventArgs|PreUpdateEventArgs $args) |
44 | { |
45 | if (!($evaluation = $args->getObject()) instanceof Evaluation) { |
46 | return; |
47 | } |
48 | |
49 | /* @var Evaluation $evaluation */ |
50 | $this->conformiteCalculator->calculEvaluationConformites($evaluation); |
51 | } |
52 | } |