Resolver::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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