1 | <?php |
||
27 | final class ReplicatedDestination implements DestinationInterface |
||
28 | { |
||
29 | |||
30 | use LoggerAwareTrait; |
||
31 | |||
32 | /** |
||
33 | * @var DestinationInterface |
||
34 | */ |
||
35 | private $master; |
||
36 | |||
37 | /** |
||
38 | * @var DestinationInterface |
||
39 | */ |
||
40 | private $slave; |
||
41 | |||
42 | /** |
||
43 | * @var bool |
||
44 | */ |
||
45 | private $atomic; |
||
46 | |||
47 | 6 | public function __construct(DestinationInterface $master, DestinationInterface $slave, $atomic = false) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 6 | public function push(BackupInterface $backup) |
|
58 | { |
||
59 | 6 | $this->master->push($backup); |
|
60 | |||
61 | try { |
||
62 | 6 | $this->slave->push($backup); |
|
63 | 5 | } catch (\Exception $e) { |
|
64 | |||
65 | 4 | if ($this->atomic) { |
|
66 | 2 | throw $e; |
|
67 | 2 | } elseif ($this->getLogger()) { |
|
68 | $this->getLogger()->error('Unable to backup to slave destination.', array( |
||
69 | 'message' => $e->getMessage(), |
||
70 | 'code' => $e->getCode(), |
||
71 | 'file' => $e->getFile(), |
||
72 | 'line' => $e->getLine(), |
||
73 | 'trace' => $e->getTrace() |
||
74 | )); |
||
75 | } |
||
76 | } |
||
77 | 4 | } |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function get($name) |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function has($name) |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function delete($name) |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function all() |
||
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | public function getIterator() |
||
135 | |||
136 | /** |
||
137 | * {@inheritdoc} |
||
138 | */ |
||
139 | public function count() |
||
143 | } |
||
144 |
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.