DecorationParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 45.45 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 39.13%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 20
loc 44
ccs 9
cts 23
cp 0.3913
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 20 31 5

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\Definition\Decoration;
15
use Fidry\LaravelYaml\DependencyInjection\Definition\DecorationInterface;
16
use Fidry\LaravelYaml\DependencyInjection\Definition\ServiceInterface;
17
use Fidry\LaravelYaml\Exception\FileLoader\InvalidArgumentException;
18
19
/**
20
 * @author Théo FIDRY <[email protected]>
21
 */
22
final class DecorationParser
23
{
24
    /**
25
     * Parses a factory service definition and return the decoration object.
26
     *
27
     * @param ServiceInterface $service
28
     * @param mixed            $decoration
29
     * @param string           $fileName file name
30
     *
31
     * @return DecorationInterface
32
     * @throws InvalidArgumentException
33
     */
34 2
    public function parse(ServiceInterface $service, $decoration, $fileName)
35
    {
36 2 View Code Duplication
        if (false === is_string($decoration['decorates'])) {
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...
37
            throw new InvalidArgumentException(
38
                sprintf(
39
                    'Parameter "decorates" for service "%s" must be the id of another service, but found "%s" instead in %s. Check your YAML syntax.',
40
                    $service->getName(),
41
                    gettype($decoration['decorates']),
42
                    $fileName
43
                )
44
            );
45
        }
46 2
        $decorates = $decoration['decorates'];
47
48 2
        $decorationInnerName = (isset($decoration['decoration_inner_name']))
49 2
            ? $decoration['decoration_inner_name']
50 2
            : null
51 1
        ;
52 2 View Code Duplication
        if (null !== $decorationInnerName && false === is_string($decorationInnerName)) {
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...
53
            throw new InvalidArgumentException(
54
                sprintf(
55
                    'Parameter "decoration_inner_name" for service "%s" must be a string if is set, but found "%s" instead in %s. Check your YAML syntax.',
56
                    $service->getName(),
57
                    gettype($decorationInnerName),
58
                    $fileName
59
                )
60
            );
61
        }
62
63 2
        return new Decoration($service, $decorates, $decorationInnerName);
64
    }
65
}
66