1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate Bundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2017 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\Event; |
11
|
|
|
|
12
|
|
|
use RunOpenCode\Bundle\ExchangeRate\Exception\LogicException; |
13
|
|
|
use Symfony\Component\EventDispatcher\Event; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class FetchSuccessEvent |
17
|
|
|
* |
18
|
|
|
* @package RunOpenCode\Bundle\ExchangeRate\Event |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class FetchSuccessEvent extends Event implements \IteratorAggregate, \ArrayAccess |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $rates; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \DateTime |
29
|
|
|
*/ |
30
|
|
|
private $date; |
31
|
|
|
|
32
|
5 |
|
public function __construct(array $rates, \DateTime $date) |
33
|
|
|
{ |
34
|
5 |
|
$this->rates = $rates; |
35
|
5 |
|
$this->date = $date; |
36
|
5 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get fetched rates. |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getRates() |
44
|
|
|
{ |
45
|
|
|
return $this->rates; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get date for which rates are fetched. |
50
|
|
|
* |
51
|
|
|
* @return \DateTime |
52
|
|
|
*/ |
53
|
|
|
public function getDate() |
54
|
|
|
{ |
55
|
|
|
return $this->date; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function getIterator() |
62
|
|
|
{ |
63
|
|
|
return new \ArrayIterator($this->rates); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function offsetExists($offset) |
70
|
|
|
{ |
71
|
|
|
return isset($this->rates[$offset]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
1 |
|
public function offsetGet($offset) |
78
|
|
|
{ |
79
|
1 |
|
return $this->rates[$offset]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function offsetSet($offset, $value) |
86
|
|
|
{ |
87
|
|
|
throw new LogicException(sprintf('Method "%s" of class "%s" can not be invoked in this context.', __FUNCTION__, __CLASS__)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function offsetUnset($offset) |
94
|
|
|
{ |
95
|
|
|
throw new LogicException(sprintf('Method "%s" of class "%s" can not be invoked in this context.', __FUNCTION__, __CLASS__)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.