Skip to content

Commit 3cb31d5

Browse files
author
Cédric Girard
committed
fixed some insight violations
1 parent 4adda28 commit 3cb31d5

File tree

7 files changed

+17
-32
lines changed

7 files changed

+17
-32
lines changed

Adapter/DoctrineCurrencyAdapter.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Lexik\Bundle\CurrencyBundle\Adapter;
44

5-
use Doctrine\ORM\EntityManager;
6-
75
/**
86
* @author Yoann Aparici <[email protected]>
97
* @author Cédric Girard <[email protected]>
@@ -15,7 +13,7 @@ class DoctrineCurrencyAdapter extends AbstractCurrencyAdapter
1513
*/
1614
public function attachAll()
1715
{
18-
16+
// nothing here
1917
}
2018

2119
/**

Adapter/EcbCurrencyAdapter.php

-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Lexik\Bundle\CurrencyBundle\Adapter;
44

5-
use Symfony\Component\DomCrawler\Crawler;
6-
75
/**
86
* @author Cédric Girard <[email protected]>
97
* @author Yoann Aparici <[email protected]>
@@ -40,7 +38,6 @@ public function attachAll()
4038
$this[$euro->getCode()] = $euro;
4139

4240
// Get other currencies
43-
// @todo timeout + try catch
4441
$xml = @simplexml_load_file($this->ecbUrl);
4542

4643
if ($xml instanceof \SimpleXMLElement) {

Adapter/OerCurrencyAdapter.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Lexik\Bundle\CurrencyBundle\Adapter;
44

55
use Lexik\Bundle\CurrencyBundle\Exception\CurrencyNotFoundException;
6-
use Symfony\Component\DomCrawler\Crawler;
76

87
/**
98
* Oer adapter, http://openexchangerates.org
@@ -35,7 +34,7 @@ public function setOerUrl($url)
3534

3635
/**
3736
* Sets the app-id
38-
*
37+
*
3938
* @param string $appId
4039
*/
4140
public function setOerAppId($appId)

Command/ImportCurrencyCommand.php

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Lexik\Bundle\CurrencyBundle\Command;
44

5-
use Lexik\Bundle\CurrencyBundle\Entity\Currency;
6-
75
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
86
use Symfony\Component\Console\Input\InputArgument;
97
use Symfony\Component\Console\Input\InputInterface;

DependencyInjection/Compiler/AdapterPass.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7-
use Symfony\Component\DependencyInjection\Definition;
87
use Symfony\Component\DependencyInjection\Reference;
98

109
/**

Tests/Unit/Twig/Extension/CurrencyExtensionTest.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,29 @@ public function setUp()
2828

2929
$factory = new AdapterFactory($this->doctrine, 'EUR', array('EUR', 'USD'), self::CURRENCY_ENTITY);
3030

31+
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
32+
$translator->expects($this->any())
33+
->method('getLocale')
34+
->will($this->returnValue('fr'));
35+
3136
$converter = new Converter($factory->createDoctrineAdapter());
3237

3338
$this->container = new Container();
3439
$this->container->set('lexik_currency.converter', $converter);
35-
36-
$this->translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
37-
$this->translator->expects($this->any())
38-
->method('getLocale')
39-
->will($this->returnValue('fr'));
40+
$this->container->set('translator', $translator);
4041
}
4142

4243
public function testConvert()
4344
{
44-
$extension = new CurrencyExtension($this->translator, $this->container);
45+
$extension = new CurrencyExtension($this->container);
4546

4647
$this->assertEquals(11.27, $extension->convert(8.666, 'USD'));
4748
$this->assertEquals(8.67, $extension->convert(8.666, 'EUR'));
4849
}
4950

5051
public function testFormat()
5152
{
52-
$extension = new CurrencyExtension($this->translator, $this->container);
53+
$extension = new CurrencyExtension($this->container);
5354

5455
$this->assertEquals('8,67 €', $extension->format(8.666));
5556
$this->assertEquals('8,67 €', $extension->format(8.666, 'EUR'));
@@ -62,7 +63,7 @@ public function testFormat()
6263

6364
public function testConvertAndFormat()
6465
{
65-
$extension = new CurrencyExtension($this->translator, $this->container);
66+
$extension = new CurrencyExtension($this->container);
6667

6768
$this->assertEquals('11,27 $', $extension->convertAndFormat(8.666, 'USD'));
6869
$this->assertEquals('11,27 $', $extension->convertAndFormat(8.666, 'USD', false));

Twig/Extension/CurrencyExtension.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Lexik\Bundle\CurrencyBundle\Twig\Extension;
44

55
use Symfony\Component\DependencyInjection\Container;
6-
use Lexik\Bundle\CurrencyBundle\Converter\Converter;
7-
use Symfony\Component\Translation\TranslatorInterface;
86

97

108
/**
@@ -15,11 +13,6 @@
1513
*/
1614
class CurrencyExtension extends \Twig_Extension
1715
{
18-
/**
19-
* @var TranslatorInterface
20-
*/
21-
protected $translator;
22-
2316
/**
2417
* @var Container
2518
*/
@@ -28,12 +21,10 @@ class CurrencyExtension extends \Twig_Extension
2821
/**
2922
* Construct.
3023
*
31-
* @param TranslatorInterface $translator
32-
* @param Container $container We need the entire container to lazy load the Converter
24+
* @param Container $container We need the entire container to lazy load the Converter
3325
*/
34-
public function __construct(TranslatorInterface $translator, Container $container)
26+
public function __construct(Container $container)
3527
{
36-
$this->translator = $translator;
3728
$this->container = $container;
3829
}
3930

@@ -52,7 +43,7 @@ public function getFilters()
5243
/**
5344
* Return Currency Converter
5445
*
55-
* @return Converter
46+
* @return \Lexik\Bundle\CurrencyBundle\Converter\Converter
5647
*/
5748
public function getConverter()
5849
{
@@ -88,7 +79,9 @@ public function format($value, $valueCurrency = null, $decimal = true, $symbol =
8879
$valueCurrency = $this->getConverter()->getDefaultCurrency();
8980
}
9081

91-
$formatter = new \NumberFormatter($this->translator->getLocale(), $symbol ? \NumberFormatter::CURRENCY : \NumberFormatter::PATTERN_DECIMAL);
82+
$locale = $this->container->get('translator')->getLocale();
83+
84+
$formatter = new \NumberFormatter($locale, $symbol ? \NumberFormatter::CURRENCY : \NumberFormatter::PATTERN_DECIMAL);
9285
$value = $formatter->formatCurrency($value, $valueCurrency);
9386

9487
if (!$decimal) {

0 commit comments

Comments
 (0)