Resolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A resolve() 0 6 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