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

JsonConverterProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 40
ccs 10
cts 14
cp 0.7143
rs 10

2 Methods

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