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

ActionPerformer::perform()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 4
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