Resolver::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Psr7Middlewares\Transformers;
4
5
/**
6
 * Generic resolver to get transformers.
7
 */
8
abstract class Resolver implements ResolverInterface
9
{
10
    protected $transformers = [];
11
12
    /**
13
     * Add a new transformer.
14
     *
15
     * @param string   $id
16
     * @param callable $resolver
17
     */
18
    public function add($id, callable $resolver)
19
    {
20
        $this->transformers[$id] = $resolver;
21
    }
22
23
    /**
24
     * Resolves the id and returns a transformer or null.
25
     *
26
     * @param string $id
27
     *
28
     * @return callable|null
29
     */
30
    public function resolve($id)
31
    {
32
        if (isset($this->transformers[$id])) {
33
            return $this->transformers[$id];
34
        }
35
    }
36
}
37