Completed
Push — master ( a814e0...392de1 )
by Tobias
24:09
created

DumperManager.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * This file is part of the BazingaGeocoderBundle package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license    MIT License
9
 */
10
namespace Bazinga\Bundle\GeocoderBundle;
11
12
use Geocoder\Dumper\Dumper;
13
14
/**
15
 * @author Markus Bachmann <[email protected]>
16
 */
17
class DumperManager
18
{
19
    /**
20
     * @var array
21
     */
22
    private $dumpers;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param array $dumpers
28
     */
29
    public function __construct(array $dumpers = array())
30
    {
31
        $this->dumpers = array();
32
33
        foreach ($dumpers as $name => $dumper) {
34
            $this->set($name, $dumper);
35
        }
36
    }
37
38
    /**
39
     * Get a dumper.
40
     *
41
     * @param string $name The name of the dumper
42
     *
43
     * @return Dumper
44
     *
45
     * @throws \RuntimeException If no dumper was found
46
     */
47 View Code Duplication
    public function get($name)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        if (!isset($this->dumpers[$name])) {
50
            throw new \RuntimeException(sprintf('The dumper "%s" does not exist', $name));
51
        }
52
53
        return $this->dumpers[$name];
54
    }
55
56
    /**
57
     * Sets a dumper.
58
     *
59
     * @param string $name   The name
60
     * @param Dumper $dumper The dumper instance
61
     */
62
    public function set($name, Dumper $dumper)
63
    {
64
        $this->dumpers[$name] = $dumper;
65
    }
66
67
    /**
68
     * Remove a dumper instance from the manager.
69
     *
70
     * @param string $name The name of the dumper
71
     *
72
     * @throws \RuntimeException If no dumper was found
73
     */
74 View Code Duplication
    public function remove($name)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        if (!isset($this->dumpers[$name])) {
77
            throw new \RuntimeException(sprintf('The dumper "%s" does not exist', $name));
78
        }
79
80
        unset($this->dumpers[$name]);
81
    }
82
83
    /**
84
     * Return true if $name exists, false otherwise.
85
     *
86
     * @param $name The name of the dumper
87
     *
88
     * @return bool
89
     */
90
    public function has($name)
91
    {
92
        return array_key_exists($name, $this->dumpers);
93
    }
94
}
95