Passed
Push — master ( 65453d...b1f8c2 )
by
unknown
16:36 queued 07:54
created

CStudentPublicationDeleteProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 22
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 16 3
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\State;
8
9
use ApiPlatform\Metadata\Operation;
10
use ApiPlatform\State\ProcessorInterface;
11
use Chamilo\CourseBundle\Entity\CStudentPublication;
12
use Doctrine\ORM\EntityManagerInterface;
13
14
/**
15
 * @implements ProcessorInterface<CStudentPublication, void>
16
 */
17
final class CStudentPublicationDeleteProcessor implements ProcessorInterface
18
{
19
    public function __construct(
20
        private readonly EntityManagerInterface $entityManager
21
    ) {}
22
23
    public function process(
24
        $data,
25
        Operation $operation,
26
        array $uriVariables = [],
27
        array $context = []
28
    ): void {
29
        if (!$data instanceof CStudentPublication) {
30
            return;
31
        }
32
33
        foreach ($data->getChildren() as $child) {
34
            $this->entityManager->remove($child);
35
        }
36
37
        $this->entityManager->remove($data);
38
        $this->entityManager->flush();
39
    }
40
}
41