Completed
Pull Request — master (#12)
by Théo
06:24 queued 03:54
created

DefinitionsParser::parseFactory()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 51
Code Lines 33

Duplication

Lines 40
Ratio 78.43 %

Code Coverage

Tests 9
CRAP Score 15.8363

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 40
loc 51
ccs 9
cts 37
cp 0.2432
rs 8.6588
cc 5
eloc 33
nc 5
nop 3
crap 15.8363

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 2
    {
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 4
                sprintf(
54 4
                    'The "services" key should contain an array in %s. Check your YAML syntax.',
55
                    $fileName
56 4
                )
57 4
            );
58
        }
59
60 32
        foreach ($content['services'] as $id => $service) {
61 32
            $this->definitionParser->parse($container, strtolower($id), $service, $fileName);
62 14
        }
63 14
    }
64
}
65