ORMDataProcessor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 23
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Bridge\Doctrine\ORM\State;
6
7
use Doctrine\Bundle\DoctrineBundle\Registry;
8
use LAG\AdminBundle\Metadata\Create;
9
use LAG\AdminBundle\Metadata\Delete;
10
use LAG\AdminBundle\Metadata\OperationInterface;
11
use LAG\AdminBundle\Metadata\Update;
12
use LAG\AdminBundle\State\DataProcessorInterface;
13
14
class ORMDataProcessor implements DataProcessorInterface
15
{
16
    public function __construct(
17
        private Registry $registry,
18
    ) {
19
    }
20
21
    public function process(
22
        mixed $data,
23
        OperationInterface $operation,
24
        array $uriVariables = [],
25
        array $context = []
26
    ): void {
27
        $manager = $this->registry->getManagerForClass($operation->getResource()->getDataClass());
0 ignored issues
show
Bug introduced by
It seems like $operation->getResource()->getDataClass() can also be of type null; however, parameter $class of Doctrine\Persistence\Abs...y::getManagerForClass() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        $manager = $this->registry->getManagerForClass(/** @scrutinizer ignore-type */ $operation->getResource()->getDataClass());
Loading history...
28
29
        if ($operation instanceof Create || $operation instanceof Update) {
30
            $manager->persist($data);
31
            $manager->flush();
32
        }
33
34
        if ($operation instanceof Delete) {
35
            $manager->remove($data);
36
            $manager->flush();
37
        }
38
    }
39
}
40