AliasParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 20 3
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\Alias;
15
use Fidry\LaravelYaml\Exception\FileLoader\InvalidArgumentException;
16
17
/**
18
 * @author Théo FIDRY <[email protected]>
19
 */
20
final class AliasParser
21
{
22
    /**
23
     * Parses a service definition alias and register it to the container.
24
     *
25
     * @param string           $id
26
     * @param array|string     $service
27
     * @param string           $fileName file name
28
     *
29
     * @throws InvalidArgumentException
30
     *
31
     * @return Alias|null
32
     */
33 28
    public function parse($id, array $service, $fileName)
34
    {
35 28
        if (false === isset($service['alias'])) {
36 22
            return null;
37
        }
38
39 8
        $aliasName = $service['alias'];
40 8
        if (false === is_string($aliasName)) {
41 2
            throw new InvalidArgumentException(
42 1
                sprintf(
43 2
                    'Parameter "alias" must be a plain name for service "%s", but found "%s" instead in %s. Check your YAML syntax.',
44 1
                    $id,
45 1
                    gettype($aliasName),
46
                    $fileName
47 1
                )
48 1
            );
49
        }
50
51 6
        return new Alias($aliasName, $id);
52
    }
53
}
54