Completed
Push — master ( 6343d0...45320b )
by Bernhard
06:10
created

JsonConverterProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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\Puli;
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 Puli
27
     */
28
    private $puli;
29
30 48
    public function __construct(Puli $puli)
31
    {
32 48
        $this->puli = $puli;
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->puli->getConfigFileConverter();
45
46
            case 'Puli\Manager\Api\Module\ModuleFile':
47 14
                return $this->puli->getLegacyModuleFileConverter();
48
49
            case 'Puli\Manager\Api\Module\RootModuleFile':
50 26
                return $this->puli->getLegacyRootModuleFileConverter();
51
52
            default:
53
                throw new InvalidArgumentException(sprintf(
54
                    'Could not find converter for class "%s".',
55
                    $className
56
                ));
57
        }
58
    }
59
}
60