Completed
Branch master (e1d486)
by Pieter
02:44
created

getSubActionsForResourceClass()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 9
c 1
b 0
f 1
nc 5
nop 1
dl 0
loc 15
rs 9.6111
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