ServiceActionValueResolver::resolve()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2015 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\ActionAutowire\HttpKernel\Controller;
11
12
use Generator;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
15
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
16
use Symplify\ActionAutowire\DependencyInjection\ServiceLocator;
17
18
final class ServiceActionValueResolver implements ArgumentValueResolverInterface
19
{
20
    /**
21
     * @var ServiceLocator
22
     */
23
    private $serviceLocator;
24
25 2
    public function __construct(ServiceLocator $serviceLocator)
26
    {
27 2
        $this->serviceLocator = $serviceLocator;
28 2
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function supports(Request $request, ArgumentMetadata $argument) : bool
34
    {
35 1
        return $this->serviceLocator->hasByType($argument->getType());
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 1
    public function resolve(Request $request, ArgumentMetadata $argument) : Generator
42
    {
43 1
        yield $this->serviceLocator->getByType($argument->getType());
44 1
    }
45
}
46