Completed
Push — master ( fbc01c...6057b3 )
by Westin
15s
created

ServiceTrait::getService()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3
1
<?php
2
3
namespace WShafer\PSR11MonoLog;
4
5
use WShafer\PSR11MonoLog\Exception\MissingConfigException;
6
use WShafer\PSR11MonoLog\Exception\MissingServiceException;
7
8
trait ServiceTrait
9
{
10
    use ContainerTrait;
11
12 3
    public function getService($name)
13
    {
14 3
        if (empty($name)) {
15 1
            throw new MissingConfigException(
16 1
                'No service name found in config'
17
            );
18
        }
19
20 2
        if (!$this->getContainer()->has($name)) {
21 1
            throw new MissingServiceException(
22 1
                'No service found for :'.$name
23
            );
24
        }
25
26 1
        return $this->getContainer()->get($name);
27
    }
28
}
29