Completed
Pull Request — master (#54)
by Tobias
36:30 queued 27:01
created

JsonConverterProvider::getJsonConverter()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
ccs 7
cts 9
cp 0.7778
rs 9.2
cc 4
eloc 12
nc 4
nop 1
crap 4.1755
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 48
    public function __construct(Container $container)
31
    {
32 48
        $this->container = $container;
33 48
    }
34
35
    /**
36
     * @param string $className The name of the class to convert.
37
     *
38
     * @return JsonConverter The JSON converter.
39
     */
40 47
    public function getJsonConverter($className)
41
    {
42
        switch ($className) {
43 47
            case 'Puli\Manager\Api\Config\ConfigFile':
44 46
                return $this->container->getConfigFileConverter();
45
46 26
            case 'Puli\Manager\Api\Module\ModuleFile':
47 14
                return $this->container->getLegacyModuleFileConverter();
48
49 26
            case 'Puli\Manager\Api\Module\RootModuleFile':
50 26
                return $this->container->getLegacyRootModuleFileConverter();
51
52
            default:
53
                throw new InvalidArgumentException(sprintf(
54
                    'Could not find converter for class "%s".',
55
                    $className
56
                ));
57
        }
58
    }
59
}
60