Completed
Pull Request — master (#47)
by Mateusz
05:43
created

JsonConverterProvider::getJsonConverter()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.2017

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 22
ccs 7
cts 11
cp 0.6364
rs 8.6737
cc 5
eloc 14
nc 5
nop 1
crap 6.2017
1
<?php
2
3
/*
4
 * This file is part of the webmozart/json package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
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 Puli\Manager\Json;
13
14
use InvalidArgumentException;
15
use Puli\Manager\Api\Container;
16
use Webmozart\Json\Conversion\JsonConverter;
17
18
/**
19
 * @since  1.0
20
 *
21
 * @author Bernhard Schussek <[email protected]>
22
 */
23
class JsonConverterProvider
24
{
25
    /**
26
     * @var Container
27
     */
28
    private $container;
29
30 50
    public function __construct(Container $container)
31
    {
32 50
        $this->container = $container;
33 50
    }
34
35
    /**
36
     * @param string $className The name of the class to convert
37
     *
38
     * @return JsonConverter The JSON converter
39
     */
40 49
    public function getJsonConverter($className)
41
    {
42
        switch ($className) {
43 49
            case 'Puli\Manager\Api\Config\ConfigFile':
44 48
                return $this->container->getConfigFileConverter();
45
46 27
            case 'Puli\Manager\Api\Module\ModuleFile':
47 15
                return $this->container->getLegacyModuleFileConverter();
48
49 27
            case 'Puli\Manager\Api\Module\RootModuleFile':
50 27
                return $this->container->getLegacyRootModuleFileConverter();
51
52
            case 'Puli\Manager\Api\Cache\CacheFile':
53
                return $this->container->getCacheFileConverter();
54
55
            default:
56
                throw new InvalidArgumentException(sprintf(
57
                    'Could not find converter for class "%s".',
58
                    $className
59
                ));
60
        }
61
    }
62
}
63