Completed
Pull Request — master (#21)
by Daniel
02:31
created

ActionPerformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B perform() 0 25 2
1
<?php
2
3
namespace Psi\Component\Grid;
4
5
use Psi\Component\ObjectAgent\AgentInterface;
6
use Psi\Component\Grid\ActionRegistry;
7
use Psi\Component\Grid\Metadata\GridMetadata;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
class ActionPerformer
11
{
12
    private $registry;
13
14
    public function __construct(ActionRegistry $registry)
15
    {
16
        $this->registry = $registry;
17
    }
18
19
    public function perform(
20
        AgentInterface $agent,
21
        GridMetadata $gridMetadata,
22
        string $actionName,
23
        array $selectedIdentifiers
24
    )
25
    {
26
        $actionMetadatas = $gridMetadata->getActions();
27
        if (!isset($actionMetadatas[$actionName])) {
28
            throw new \InvalidArgumentException(sprintf(
29
                'Action "%s" is not available for class "%s". Availabile actions: "%s"',
30
                $actionName, $gridMetadata->getClassMetadata()->name, implode('", "', array_keys($actionMetadatas))
31
            ));
32
        }
33
34
        $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...
35
36
        $actionMetadata = $actionMetadatas[$actionName];
37
        $action = $this->registry->get($actionMetadata->getType());
38
        $options = new OptionsResolver();
39
        $action->configureOptions($options);
40
        $options = $options->resolve($actionMetadata->getOptions());
41
42
        $action->perform($agent, $collection, $options);
43
    }
44
}
45