InterceptorEncapsulator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A encapsulate() 0 18 4
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