DefinitionParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 10
loc 45
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B parse() 10 22 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the LaravelYaml package.
5
 *
6
 * (c) Théo FIDRY <[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 Fidry\LaravelYaml\FileLoader\Parser\Yaml\Util;
13
14
use Fidry\LaravelYaml\DependencyInjection\Builder\ContainerBuilder;
15
use Fidry\LaravelYaml\DependencyInjection\Definition\Alias;
16
use Fidry\LaravelYaml\Exception\FileLoader\InvalidArgumentException;
17
use Fidry\LaravelYaml\FileLoader\Parser\Resolver\ResolverInterface;
18
19
/**
20
 * @author Théo FIDRY <[email protected]>
21
 */
22
final class DefinitionParser
23
{
24
    /**
25
     * @var ServiceParser
26
     */
27
    private $serviceParser;
28
29 44
    public function __construct(ResolverInterface $serviceResolver)
30
    {
31 44
        $this->serviceParser = new ServiceParser($serviceResolver);
32 44
    }
33
34
    /**
35
     * Parses a service definition and register it to the container.
36
     *
37
     * @param ContainerBuilder $container
38
     * @param string           $id
39
     * @param array|string     $service
40
     * @param string           $fileName file name
41
     *
42
     * @throws InvalidArgumentException
43
     */
44 32
    public function parse(ContainerBuilder $container, $id, $service, $fileName)
45
    {
46 32
        if (is_string($service) && 0 === strpos($service, '@')) {
47 4
            $alias = new Alias($id, substr($service, 1));
48 4
            $container->addAlias($alias);
49
50 4
            return;
51
        }
52
53 30 View Code Duplication
        if (false === is_array($service)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54 2
            throw new InvalidArgumentException(
55 1
                sprintf(
56 2
                    'A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.',
57 1
                    gettype($service),
58 1
                    $id,
59
                    $fileName
60 1
                )
61 1
            );
62
        }
63
64 29
        $this->serviceParser->parse($container, $id, $service, $fileName);
65 13
    }
66
}
67