Completed
Pull Request — master (#12)
by Théo
11:36
created

AutowiringTypesParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 20.45 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 9
loc 44
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 9 33 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\Exception\FileLoader\InvalidArgumentException;
15
16
/**
17
 * @author Théo FIDRY <[email protected]>
18
 */
19
final class AutowiringTypesParser
20
{
21
    /**
22
     * @param string $id
23
     * @param array  $service
24
     * @param string $fileName
25
     *
26
     * @return array
27
     * @throws InvalidArgumentException
28
     */
29
    public function parse($id, $service, $fileName)
30
    {
31
        if (false === isset($service['autowiringTypes'])) {
32
            return [];
33
        }
34
35 View Code Duplication
        if (false === is_array($service['autowiringTypes'])) {
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...
36
            throw new InvalidArgumentException(
37
                sprintf(
38
                    'Parameter "autowiringTypes" must be an array for service "%s" in %s. Check your YAML syntax.',
39
                    $id,
40
                    $fileName
41
                )
42
            );
43
        }
44
45
        $autowiringTypes = [];
46
        foreach ($service['autowiringTypes'] as $autowiringType) {
47
            if (false === is_string($autowiringType)) {
48
                throw new InvalidArgumentException(
49
                    sprintf(
50
                        'A "autowiringType" entry must be a FQCN for service "%s" in %s. Check your YAML syntax.',
51
                        $id,
52
                        $fileName
53
                    )
54
                );
55
            }
56
57
            $autowiringTypes[$autowiringType] = true;
58
        }
59
60
        return array_keys($autowiringTypes);
61
    }
62
}
63