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

JsonConverterProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
ccs 8
cts 12
cp 0.6667
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getJsonConverter() 0 19 4
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