TransformationProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A resolve() 0 5 2
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[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 ICanBoogie\Transformation\PSR;
13
14
use ICanBoogie\Transformation\TransformationProviderAbstract;
15
use Psr\Container\ContainerInterface;
16
17
/**
18
 * Provides transformations from a container.
19
 */
20
class TransformationProvider extends TransformationProviderAbstract
21
{
22
    /**
23
     * @var ContainerInterface
24
     */
25
    private $container;
26
27
    /**
28
     * @var array
29
     */
30
    private $cache = [];
31
32
    /**
33
     * @inheritdoc
34
     * @param ContainerInterface $container
35
     */
36
    public function __construct(array $transformations, ContainerInterface $container)
37
    {
38
        $this->container = $container;
39
40
        parent::__construct($transformations);
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    protected function resolve($transformation): callable
47
    {
48
        $resolved = &$this->cache[$transformation];
49
50
        return $resolved ?: $resolved = $this->container->get($transformation);
51
    }
52
}
53