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

BaseReferenceResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 5
c 2
b 0
f 2
lcom 0
cbo 3
dl 0
loc 22
ccs 10
cts 11
cp 0.9091
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B resolve() 0 16 5
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