Completed
Push — master ( 4f3015...33d383 )
by Kamil
08:24 queued 01:12
created

ArgumentResolver::resolveArgument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
declare(strict_types=1);
3
namespace VirCom\Behat3ZendFramework3Extension\Context\Argument;
4
5
use Behat\Behat\Context\Argument\ArgumentResolver as ArgumentResolverInterface;
6
7
use Zend\Mvc\ApplicationInterface;
8
9
use ReflectionClass;
10
11
class ArgumentResolver implements
12
    ArgumentResolverInterface
13
{
14
    /**
15
     * @var ApplicationInterface
16
     */
17
    protected $application;
18
19
    /**
20
     * @param ApplicationInterface $application
21
     */
22
    public function __construct(
23
        ApplicationInterface $application
24
    ) {
25
        $this->application = $application;
26
    }
27
28
    /**
29
     * @param ReflectionClass $classReflection
30
     * @param array $arguments
31
     * @return array
32
     *
33
     * @SuppressWarnings("unused")
34
     */
35
    public function resolveArguments(
36
        ReflectionClass $classReflection,
37
        array $arguments
38
    ): array {
39
        $result = [];
40
41
        foreach ($arguments as $key => $name) {
42
            $result[$key] = $this->resolveArgument($name);
43
        }
44
45
        return $result;
46
    }
47
48
    /**
49
     * @param string $argument
50
     * @return mixed
51
     */
52
    protected function resolveArgument(
53
        string $argument
54
    ) {
55
        if (substr($argument, 0, 1) === "@") {
56
            return $this->application
57
                ->getServiceManager()
58
                ->get(substr($argument, 1));
59
        }
60
61
        return $argument;
62
    }
63
}
64