Passed
Branch 3.3 (35580f)
by Pieter
15:26
created

SubActionContainer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 36
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubActionsForResourceClass() 0 15 5
1
<?php
2
3
4
namespace W2w\Lib\Apie\OpenApiSchema\SubActions;
5
6
use ReflectionMethod;
7
8
class SubActionContainer
9
{
10
    /**
11
     * @var object[][]
12
     */
13
    private $input;
14
15
    /**
16
     * @var SubActionFactory
17
     */
18
    private $subActionFactory;
19
20
    /**
21
     * @param object[][] $input
22
     */
23
    public function __construct(array $input, SubActionFactory $subActionFactory)
24
    {
25
        $this->input = $input;
26
        $this->subActionFactory = $subActionFactory;
27
    }
28
29
    public function getSubActionsForResourceClass(string $resourceClass): array
30
    {
31
        $res = [];
32
        foreach ($this->input as $actionName => $objects) {
33
            foreach ($objects as $object) {
34
                if (is_callable([$object, 'handle'])) {
35
                    $reflProp = new ReflectionMethod($object, 'handle');
36
                    $subAction = $this->subActionFactory->createFromReflectionMethod($actionName, $resourceClass, $reflProp, $object);
37
                    if ($subAction) {
38
                        $res[$actionName] = $subAction;
39
                    }
40
                }
41
            }
42
        }
43
        return $res;
44
    }
45
}
46