InterceptorEncapsulator::encapsulate()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.2
cc 4
eloc 10
nc 3
nop 3
1
<?php
2
namespace DICIT\Encapsulators;
3
4
use DICIT\Encapsulator;
5
use DICIT\Container;
6
7
class InterceptorEncapsulator implements Encapsulator
8
{
9
10
    public function encapsulate(Container $container, $object, array $serviceConfig)
11
    {
12
        if (array_key_exists('interceptor', $serviceConfig)) {
13
            foreach ($serviceConfig['interceptor'] as $interceptorName) {
14
                $interceptor = $container->resolve($interceptorName);
15
16
                if (! is_object($interceptor)) {
17
                    throw new \RuntimeException(
18
                        'The interceptor ' . $interceptorName . ' does not reference a known service');
19
                }
20
21
                $interceptor->setDecorated($object);
22
                $object = $interceptor;
23
            }
24
        }
25
26
        return $object;
27
    }
28
}
29