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

DefinitionsParser::parseDefinition()   B

Complexity

Conditions 9
Paths 15

Size

Total Lines 55
Code Lines 34

Duplication

Lines 10
Ratio 18.18 %

Code Coverage

Tests 41
CRAP Score 9

Importance

Changes 5
Bugs 2 Features 3
Metric Value
c 5
b 2
f 3
dl 10
loc 55
ccs 41
cts 41
cp 1
rs 7.2446
cc 9
eloc 34
nc 15
nop 4
crap 9

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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;
13
14
use Fidry\LaravelYaml\DependencyInjection\Builder\ContainerBuilder;
15
use Fidry\LaravelYaml\Exception\FileLoader\InvalidArgumentException;
16
use Fidry\LaravelYaml\FileLoader\Parser\Resolver\ResolverInterface;
17
use Fidry\LaravelYaml\FileLoader\Parser\Resolver\ServiceResolver;
18
use Fidry\LaravelYaml\FileLoader\Parser\Yaml\Util\DefinitionParser;
19
20
/**
21
 * @author Théo FIDRY <[email protected]>
22
 */
23
final class DefinitionsParser
24
{
25
    /**
26
     * @var DefinitionParser
27
     */
28
    private $definitionParser;
29
30 44
    public function __construct(ResolverInterface $serviceResolver = null)
31 1
    {
32 44
        $serviceResolver = (null === $serviceResolver) ? new ServiceResolver() : $serviceResolver;
33 44
        $this->definitionParser = new DefinitionParser($serviceResolver);
34 44
    }
35
36
    /**
37
     * Parses service definitions and register them to the container.
38
     *
39
     * @param ContainerBuilder $container
40
     * @param array            $content  YAML file content
41
     * @param string           $fileName file name
42
     *
43
     * @throws InvalidArgumentException
44
     */
45 44
    public function parse(ContainerBuilder $container, $content, $fileName)
46
    {
47 44
        if (!isset($content['services'])) {
48 8
            return;
49
        }
50
51 36
        if (!is_array($content['services'])) {
52 4
            throw new InvalidArgumentException(
53 2
                sprintf(
54 4
                    'The "services" key should contain an array in %s. Check your YAML syntax.',
55
                    $fileName
56 2
                )
57 2
            );
58
        }
59
60 32
        foreach ($content['services'] as $id => $service) {
61 32
            $this->definitionParser->parse($container, strtolower($id), $service, $fileName);
62 7
        }
63 14
    }
64
}
65