ResolverChain   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 42
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A addResolver() 4 4 1
A getResolver() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Copyright 2014 Jonathan Bouzekri. All rights reserved.
5
 *
6
 * @copyright Copyright 2014 Jonathan Bouzekri <[email protected]>
7
 * @license https://github.com/jbouzekri/FileUploaderBundle/blob/master/LICENSE
8
 * @link https://github.com/jbouzekri/FileUploaderBundle
9
 */
10
11
namespace Jb\Bundle\FileUploaderBundle\Service;
12
13
use Jb\Bundle\FileUploaderBundle\Exception\JbFileUploaderException;
14
use Jb\Bundle\FileUploaderBundle\Service\Resolver\ResolverInterface;
15
16
/**
17
 * ResolverChain
18
 *
19
 * @author jobou
20
 */
21 View Code Duplication
class ResolverChain
22
{
23
    /**
24
     * @var array
25
     */
26
    private $resolvers;
27
28
    /**
29
     * Constructor
30
     */
31
    public function __construct()
32
    {
33
        $this->resolvers = array();
34
    }
35
36
    /**
37
     * Add a resolver
38
     *
39
     * @param \Jb\Bundle\FileUploaderBundle\Service\Resolver\ResolverInterface $resolver
40
     */
41
    public function addResolver(ResolverInterface $resolver, $alias)
42
    {
43
        $this->resolvers[$alias] = $resolver;
44
    }
45
46
    /**
47
     *
48
     * @param string $alias
49
     *
50
     * @return \Jb\Bundle\FileUploaderBundle\Service\Resolver\ResolverInterface
51
     *
52
     * @throws \Jb\Bundle\FileUploaderBundle\Exception\JbFileUploaderException
53
     */
54
    public function getResolver($alias)
55
    {
56
        if (array_key_exists($alias, $this->resolvers)) {
57
            return $this->resolvers[$alias];
58
        }
59
60
        throw new JbFileUploaderException('Unknown resolver ' . $alias);
61
    }
62
}
63