ArgumentParserFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 3
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
 */
10
11
namespace Kocuj\Di\ArgumentParser;
12
13
use Kocuj\Di\ArgumentParser\Service\Service;
14
use Kocuj\Di\ArgumentParser\Value\Value;
15
use Kocuj\Di\Container\ContainerInterface;
16
17
/**
18
 * Service argument parser factory
19
 *
20
 * @package Kocuj\Di\ArgumentParser
21
 */
22
class ArgumentParserFactory implements ArgumentParserFactoryInterface
23
{
24
    /**
25
     * Create object with parser for service argument
26
     *
27
     * @param ContainerInterface $container Dependency injection container for services
28
     * @param string $id Service identifier
29
     * @param array $argument Service argument to parse
30
     * @throws Exception
31
     * @return ArgumentParserInterface Object with service argument parser
32
     * @see \Kocuj\Di\ArgumentParser\ArgumentParserInterface::create()
33
     * @codeCoverageIgnore
34
     */
35
    public function create(ContainerInterface $container, string $id, array $argument): ArgumentParserInterface
36
    {
37
        // exit
38
        switch ($argument['type']) {
39
            case 'service':
40
                return new Service($container, $id, $argument);
41
            case 'value':
42
                return new Value($argument);
43
            default:
44
                throw new Exception(sprintf('Unknown argument type "%s"', $argument['type']));
45
        }
46
    }
47
}
48