Completed
Push — master ( 344583...2d30d0 )
by Bogdan
11s
created

FunctionDecorator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 29
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A decorate() 0 10 2
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/js-sandbox PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the
11
 * LICENSE file that was distributed with this source or visit
12
 * http://opensource.org/licenses/MIT
13
 */
14
15
16
namespace Pinepain\JsSandbox\Wrappers\FunctionComponents;
17
18
19
use Pinepain\JsSandbox\Decorators\DecoratorsCollectionInterface;
20
use Pinepain\JsSandbox\Specs\FunctionSpecInterface;
21
use Pinepain\JsSandbox\Wrappers\FunctionComponents\Runtime\ExecutionContextInterface;
22
23
24
class FunctionDecorator implements FunctionDecoratorInterface
25
{
26
    /**
27
     * @var DecoratorsCollectionInterface
28
     */
29
    private $collection;
30
31
    /**
32
     * @param DecoratorsCollectionInterface $collection
33
     */
34
    public function __construct(DecoratorsCollectionInterface $collection)
35
    {
36
        $this->collection = $collection;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function decorate(callable $callback, FunctionSpecInterface $spec, ExecutionContextInterface $exec): callable
43
    {
44
        foreach ($spec->getDecorators() as $decorator_spec) {
45
            $decorator = $this->collection->get($decorator_spec->getName());
46
47
            $callback = $decorator->decorate($callback, $exec);
48
        }
49
50
        return $callback;
51
    }
52
}
53