Completed
Push — master ( 10310e...1cabb1 )
by Théo
8s
created

BaseReferenceResolver::resolve()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.0187

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 10
cts 11
cp 0.9091
rs 8.8571
cc 5
eloc 11
nc 5
nop 2
crap 5.0187
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\DependencyInjection\Resolver;
13
14
use Fidry\LaravelYaml\DependencyInjection\Definition\Reference;
15
use Fidry\LaravelYaml\Exception\ServiceNotFoundException;
16
use Illuminate\Contracts\Foundation\Application;
17
18
/**
19
 * @author Théo FIDRY <[email protected]>
20
 */
21
final class BaseReferenceResolver implements ReferenceResolverInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 12
    public function resolve(Reference $reference, Application $application)
27
    {
28
        try {
29 12
            return $application->make($reference->getId());
30 9
        } catch (\Exception $exception) {
31 6
            switch (true) {
32 9
                case $reference->throwExceptionOnInvalidBehaviour():
33 3
                    throw new ServiceNotFoundException(sprintf('Could not find service "%s"', $reference->getId()));
34
35 6
                case $reference->returnNullOnInvalidBehaviour():
36 5
                case $reference->ignoreOnInvalidBehaviour():
37 4
                default:
38 6
                    return null;
39
            }
40
        }
41
    }
42
}
43