DeleteAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A perform() 0 22 3
A configureOptions() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid\Action;
6
7
use Psi\Component\Grid\ActionInterface;
8
use Psi\Component\Grid\ActionResponse;
9
use Psi\Component\Grid\ActionResponseInterface;
10
use Psi\Component\ObjectAgent\AgentInterface;
11
use Symfony\Component\OptionsResolver\OptionsResolver;
12
13
class DeleteAction implements ActionInterface
14
{
15
    public function perform(AgentInterface $agent, string $classFqn, array $identifiers, array $options): ActionResponseInterface
16
    {
17
        $collection = $agent->findMany($identifiers, $classFqn);
18
19
        $errors = [];
20
        $affected = count($collection);
21
22
        try {
23
            foreach ($collection as $object) {
24
                $agent->remove($object);
25
            }
26
            $agent->flush();
27
        } catch (\Exception $e) {
28
            $errors[] = $e->getMessage();
29
            $affected = 0;
30
        }
31
32
        return ActionResponse::create([
33
            'errors' => $errors,
34
            'affected' => $affected,
35
        ]);
36
    }
37
38
    public function configureOptions(OptionsResolver $options)
39
    {
40
    }
41
}
42