1 | <?php |
||
24 | class PriceExtension extends \Twig_Extension implements LoggerAwareInterface |
||
25 | { |
||
26 | use LoggerAwareTrait; |
||
27 | |||
28 | /** |
||
29 | * Extension name |
||
30 | */ |
||
31 | const NAME = 'price_extension'; |
||
32 | |||
33 | /** |
||
34 | * @var string Currency sign. |
||
35 | */ |
||
36 | private $currencySign; |
||
37 | |||
38 | /** |
||
39 | * @var string Decimal point separator. |
||
40 | */ |
||
41 | private $decPointSeparator; |
||
42 | |||
43 | /** |
||
44 | * @var string Thousands separator. |
||
45 | */ |
||
46 | private $thousandsSeparator; |
||
47 | |||
48 | /** |
||
49 | * @var null Currency. |
||
50 | */ |
||
51 | private $currency = null; |
||
52 | |||
53 | /** |
||
54 | * @var CurrencyExchangeService Service which provide currency exchange rates. |
||
55 | */ |
||
56 | private $currencyService = null; |
||
57 | |||
58 | /** |
||
59 | * @var array Contains formats for each currency. |
||
60 | */ |
||
61 | private $formatsMap; |
||
62 | |||
63 | /** |
||
64 | * @var array Array of currencies to be listed in twig while using the "list" functions. |
||
65 | */ |
||
66 | private $toListMap; |
||
67 | |||
68 | /** |
||
69 | * @var string String containing the default currency_list template |
||
70 | */ |
||
71 | private $currency_list; |
||
72 | |||
73 | /** |
||
74 | * @var string String containing the default price_list template |
||
75 | */ |
||
76 | private $price_list; |
||
77 | |||
78 | /** |
||
79 | 27 | * Constructor. |
|
80 | * |
||
81 | * @param string $currencySign |
||
82 | * @param string $decPointSeparator |
||
83 | * @param string $thousandsSeparator |
||
84 | * @param string $currency_list |
||
85 | * @param string $price_list |
||
86 | * @param array $currency |
||
87 | 27 | * @param array $formatsMap |
|
88 | 27 | * @param array $toListMap |
|
89 | 27 | */ |
|
90 | 27 | public function __construct( |
|
109 | |||
110 | 2 | /** |
|
111 | 2 | * @return \Twig_SimpleFilter[] |
|
112 | */ |
||
113 | 2 | public function getFilters() |
|
132 | |||
133 | 2 | /** |
|
134 | 2 | * @return \Twig_SimpleFunction[] |
|
135 | */ |
||
136 | public function getFunctions() |
||
151 | |||
152 | /** |
||
153 | * Returns formatted price. |
||
154 | * |
||
155 | 21 | * @param float $price |
|
156 | * @param int $decimals |
||
157 | 21 | * @param string $toCurrency |
|
158 | 21 | * @param string $fromCurrency |
|
159 | * @param string $customFormat |
||
160 | 20 | * @param string $date |
|
161 | 20 | * |
|
162 | 1 | * @return string |
|
163 | 1 | */ |
|
164 | 1 | public function getFormattedPrice( |
|
212 | 7 | ||
213 | 7 | /** |
|
214 | 7 | * Returns specified prices formatted by a specified template. |
|
215 | 7 | * |
|
216 | 7 | * @param \Twig_Environment $environment |
|
217 | * @param int $price |
||
218 | 7 | * @param string $template |
|
219 | * @param null $fromCurrency |
||
220 | 7 | * @param string $date |
|
221 | 7 | * |
|
222 | 7 | * @return string |
|
223 | 7 | */ |
|
224 | public function getPriceList( |
||
247 | 1 | ||
248 | 1 | /** |
|
249 | * Returns all available currencies. |
||
250 | * |
||
251 | * @param \Twig_Environment $environment |
||
252 | * @param string $template |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | 2 | public function getCurrencyList($environment, $template = '') |
|
275 | |||
276 | /** |
||
277 | * Returns name of the extension. |
||
278 | * |
||
279 | * @return string |
||
280 | 21 | */ |
|
281 | public function getName() |
||
285 | |||
286 | /** |
||
287 | * @param null $currency |
||
288 | 2 | */ |
|
289 | public function setCurrency($currency) |
||
293 | |||
294 | /** |
||
295 | * @return string |
||
296 | 1 | */ |
|
297 | public function getCurrency() |
||
301 | |||
302 | /** |
||
303 | * @param CurrencyExchangeService $currencyService |
||
304 | 1 | */ |
|
305 | public function setCurrencyExchangeService($currencyService) |
||
309 | |||
310 | /** |
||
311 | * @param array $toListMap |
||
312 | */ |
||
313 | public function setToListMap($toListMap) |
||
317 | |||
318 | /** |
||
319 | * @param array $formatsMap |
||
320 | */ |
||
321 | public function setFormatsMap($formatsMap) |
||
325 | } |
||
326 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.