Completed
Push — master ( 18069b...6f42c8 )
by Tomáš
05:04
created

ServiceActionValueResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 28
ccs 0
cts 12
cp 0
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
    public function __construct(ServiceLocator $serviceLocator)
26
    {
27
        $this->serviceLocator = $serviceLocator;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function supports(Request $request, ArgumentMetadata $argument) : bool
34
    {
35
        return $this->serviceLocator->hasByType($argument->getType());
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function resolve(Request $request, ArgumentMetadata $argument) : Generator
42
    {
43
        yield $this->serviceLocator->getByType($argument->getType());
44
    }
45
}
46