Completed
Push — master ( acaf00...ffceb6 )
by Tomáš
03:10
created

ServiceActionValueResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A supports() 0 4 1
A resolve() 0 4 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