Completed
Push — master ( 933a2a...d1c0c8 )
by Lukas Kahwe
05:29
created

ContainerDecoderProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 4
c 4
b 2
f 0
lcom 1
cbo 1
dl 0
loc 39
ccs 9
cts 12
cp 0.75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A supports() 0 4 1
A getDecoder() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\Decoder;
13
14
use Symfony\Component\DependencyInjection\ContainerInterface;
15
16
/**
17
 * Provides encoders through the Symfony2 DIC.
18
 *
19
 * @author Igor Wiedler <[email protected]>
20
 */
21
class ContainerDecoderProvider implements DecoderProviderInterface
22
{
23
    private $container;
24
    private $decoders;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param ContainerInterface $container The container from which the actual decoders are retrieved
30
     * @param array              $decoders  List of key (format) value (service ids) of decoders
31
     */
32 30
    public function __construct(ContainerInterface $container, array $decoders)
33
    {
34 30
        $this->container = $container;
35 30
        $this->decoders = $decoders;
36 30
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 10
    public function supports($format)
42
    {
43 10
        return isset($this->decoders[$format]);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 7
    public function getDecoder($format)
50
    {
51 7
        if (!$this->supports($format)) {
52
            throw new \InvalidArgumentException(
53
                sprintf("Format '%s' is not supported by ContainerDecoderProvider.", $format)
54
            );
55
        }
56
57 7
        return $this->container->get($this->decoders[$format]);
58
    }
59
}
60