Completed
Pull Request — master (#12)
by Théo
03:12 queued 46s
created

DecorationParser::parse()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 31
Code Lines 20

Duplication

Lines 20
Ratio 64.52 %

Code Coverage

Tests 9
CRAP Score 10.6382

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 31
ccs 9
cts 23
cp 0.3913
rs 8.439
cc 5
eloc 20
nc 5
nop 3
crap 10.6382
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