AutowiringTypesParser::parse()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 33
Code Lines 19

Duplication

Lines 9
Ratio 27.27 %

Code Coverage

Tests 22
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 33
ccs 22
cts 22
cp 1
rs 8.439
cc 5
eloc 19
nc 5
nop 3
crap 5
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 16
    public function parse($id, $service, $fileName)
30
    {
31 16
        if (false === isset($service['autowiringTypes'])) {
32 10
            return [];
33
        }
34
35 6 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 2
            throw new InvalidArgumentException(
37 1
                sprintf(
38 2
                    'Parameter "autowiringTypes" must be an array for service "%s" in %s. Check your YAML syntax.',
39 1
                    $id,
40
                    $fileName
41 1
                )
42 1
            );
43
        }
44
45 4
        $autowiringTypes = [];
46 4
        foreach ($service['autowiringTypes'] as $autowiringType) {
47 4
            if (false === is_string($autowiringType)) {
48 2
                throw new InvalidArgumentException(
49 1
                    sprintf(
50 2
                        'A "autowiringType" entry must be a FQCN for service "%s" in %s. Check your YAML syntax.',
51 1
                        $id,
52
                        $fileName
53 1
                    )
54 1
                );
55
            }
56
57 2
            $autowiringTypes[$autowiringType] = true;
58 1
        }
59
60 2
        return array_keys($autowiringTypes);
61
    }
62
}
63