Passed
Push — master ( 4d9c37...7cec18 )
by Dominik
13:53
created

ArgumentParserFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 3
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * ArgumentParserFactory.php
5
 *
6
 * @author Dominik Kocuj
7
 * @license https://opensource.org/licenses/MIT The MIT License
8
 * @copyright Copyright (c) 2017-2018 kocuj.pl
9
 * @package kocuj_di
10
 */
11
namespace Kocuj\Di\ArgumentParser;
12
13
use Kocuj\Di\ArgumentParser\Value\Value;
14
use Kocuj\Di\ArgumentParser\Service\Service;
15
use Kocuj\Di\Container\ContainerInterface;
16
17
/**
18
 * Service argument parser factory
19
 */
20
class ArgumentParserFactory implements ArgumentParserFactoryInterface
21
{
22
23
    /**
24
     * Create object with parser for service argument
25
     *
26
     * @param ContainerInterface $container
27
     *            Dependency injection container for services
28
     * @param string $id
29
     *            Service identifier
30
     * @param array $argument
31
     *            Service argument to parse
32
     * @throws Exception
33
     * @return ArgumentParserInterface Object with service argument parser
34
     * @see \Kocuj\Di\ArgumentParser\ArgumentParserInterface::create() @codeCoverageIgnore
35
     */
36
    public function create(ContainerInterface $container, string $id, array $argument): ArgumentParserInterface
37
    {
38
        // exit
39
        switch ($argument['type']) {
40
            case 'service':
41
                return new Service($container, $id, $argument);
42
            case 'value':
43
                return new Value($argument);
44
            default:
45
                throw new Exception(sprintf('Unknown argument type "%s"', $argument['type']));
46
        }
47
    }
48
}
49