Completed
Push — master ( 406296...0a0b96 )
by Daniel
07:00 queued 04:29
created

ActionPerformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B perform() 0 24 2
1
<?php
2
3
namespace Psi\Component\Grid;
4
5
use Psi\Component\Grid\Metadata\GridMetadata;
6
use Psi\Component\ObjectAgent\AgentInterface;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
class ActionPerformer
10
{
11
    private $registry;
12
13
    public function __construct(ActionRegistry $registry)
14
    {
15
        $this->registry = $registry;
16
    }
17
18
    public function perform(
19
        AgentInterface $agent,
20
        GridMetadata $gridMetadata,
21
        string $actionName,
22
        array $selectedIdentifiers
23
    ) {
24
        $actionMetadatas = $gridMetadata->getActions();
25
        if (!isset($actionMetadatas[$actionName])) {
26
            throw new \InvalidArgumentException(sprintf(
27
                'Action "%s" is not available for class "%s". Availabile actions: "%s"',
28
                $actionName, $gridMetadata->getClassMetadata()->name, implode('", "', array_keys($actionMetadatas))
29
            ));
30
        }
31
32
        $collection = $agent->findMany($selectedIdentifiers, $gridMetadata->getClassMetadata()->name);
0 ignored issues
show
Bug introduced by
The method findMany() does not seem to exist on object<Psi\Component\ObjectAgent\AgentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
34
        $actionMetadata = $actionMetadatas[$actionName];
35
        $action = $this->registry->get($actionMetadata->getType());
36
        $options = new OptionsResolver();
37
        $action->configureOptions($options);
38
        $options = $options->resolve($actionMetadata->getOptions());
39
40
        $action->perform($agent, $collection, $options);
41
    }
42
}
43