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

ClassParser::parse()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 10
Ratio 41.67 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 24
ccs 0
cts 17
cp 0
rs 8.9713
cc 3
eloc 15
nc 3
nop 3
crap 12
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 ClassParser
20
{
21
    /**
22
     * @param string $id
23
     * @param array  $service
24
     * @param string $fileName
25
     *
26
     * @return string
27
     * @throws InvalidArgumentException
28
     */
29
    public function parse($id, $service, $fileName)
30
    {
31
        if (false === isset($service['class'])) {
32
            throw new InvalidArgumentException(
33
                sprintf(
34
                    'Parameter "class" missing for service "%s" in %s. Check your YAML syntax.',
35
                    $id,
36
                    $fileName
37
                )
38
            );
39
        }
40 View Code Duplication
        if (false === is_string($service['class'])) {
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...
41
            throw new InvalidArgumentException(
42
                sprintf(
43
                    'Parameter "class" must be a FQCN for service "%s", but found "%s" instead in %s. Check your YAML syntax.',
44
                    $id,
45
                    gettype($service['class']),
46
                    $fileName
47
                )
48
            );
49
        }
50
51
        return $service['class'];
52
    }
53
}
54