Skip to content

Commit

Permalink
CS Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danizord committed Jun 20, 2016
1 parent 23f76f0 commit df26ab0
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ before_script:
script:
- composer install --prefer-source
- vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
- vendor/bin/php-cs-fixer fix -v --dry-run ./test
- vendor/bin/php-cs-fixer fix -v --fixers=-empty_return --diff --dry-run ./src
- vendor/bin/php-cs-fixer fix -v --fixers=-empty_return --diff --dry-run ./test

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
Expand Down
7 changes: 3 additions & 4 deletions src/DBAL/Types/CurrencyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Types\StringType;
use Money\Currency;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
Expand All @@ -14,17 +13,17 @@
class CurrencyType extends StringType
{
const NAME = 'currency';

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getName()
{
return self::NAME;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Filter/AmountFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Money\InvalidArgumentException;
use Money\Money;
use Zend\Filter\AbstractFilter;
use Zend\Filter\Exception;

/**
* @author Gabriel Schmitt <[email protected]>
Expand All @@ -14,10 +13,11 @@
class AmountFilter extends AbstractFilter
{
/**
* {@inheritDoc}
* {@inheritdoc}
*
* @throws InvalidArgumentException
* @return int
*
* @return int|null
*/
public function filter($value)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Form/Element/Factory/CurrencySelectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ class CurrencySelectFactory
{
/**
* @param FormElementManager $formElementManager
*
* @return CurrencySelect
*/
public function __invoke(FormElementManager $formElementManager)
{
$serviceManager = $formElementManager->getServiceLocator();
$config = $serviceManager->get('Config');

if (! isset($config['money']['currencies'])) {
if (!isset($config['money']['currencies'])) {
throw new InvalidArgumentException('Couldn\'t find currencies configuration.');
}

Expand Down
14 changes: 7 additions & 7 deletions src/Form/MoneyFieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@
use ZFBrasil\DoctrineMoneyModule\InputFilter\MoneyInputFilter;

/**
* Money form element that will make it very easy to work with money and currencies
* Money form element that will make it very easy to work with money and currencies.
*
* @author Fábio Carneiro <[email protected]>
* @license MIT
*/
class MoneyFieldset extends Fieldset implements InputFilterProviderInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function init()
{
$this->add([
'type' => Number::class,
'name' => 'amount',
'options' => [
'label' => 'Amount'
'label' => 'Amount',
],
'attributes' => [
'step' => '0.01',
]
],
]);

$this->add([
'type' => CurrencySelect::class,
'name' => 'currency',
'options' => [
'label' => 'Currency'
]
'label' => 'Currency',
],
]);
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getInputFilterSpecification()
{
Expand Down
10 changes: 5 additions & 5 deletions src/Hydrator/MoneyHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
use Money\Currency;

/**
* Hydrator for Money object
* Hydrator for Money object.
*
* @author Fábio Carneiro <[email protected]>
* @license MIT
*/
class MoneyHydrator implements HydratorInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function extract($object)
{
return [
'amount' => $object->getAmount(),
'currency' => $object->getCurrency()->getName()
'currency' => $object->getCurrency()->getName(),
];
}

/**
* {@inheritDoc}
* {@inheritdoc}
*
* @return Money
* @return Money|null
*/
public function hydrate(array $data, $object)
{
Expand Down
14 changes: 7 additions & 7 deletions src/InputFilter/MoneyInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@
class MoneyInputFilter extends InputFilter
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function init()
{
$this->add([
'name' => 'amount',
'required' => true,
'filters' => [
['name' => AmountFilter::class]
['name' => AmountFilter::class],
],
'validators' => [
['name' => NotEmpty::class]
]
['name' => NotEmpty::class],
],
]);

$this->add([
'name' => 'currency',
'required' => true,
'filters' => [
['name' => StringToUpper::class]
['name' => StringToUpper::class],
],
'validators' => [
['name' => NotEmpty::class]
]
['name' => NotEmpty::class],
],
]);
}
}
4 changes: 2 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
class Module implements ConfigProviderInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getConfig()
{
return require __DIR__ . '/../config/module.config.php';
return require __DIR__.'/../config/module.config.php';
}
}
13 changes: 13 additions & 0 deletions src/ODM/MongoDB/Types/CurrencyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ class CurrencyType extends Type
{
const NAME = 'currency';

/**
* @return string
*/
public function getName()
{
return self::NAME;
}

/**
* @param mixed $value
*
* @return null|string
*/
public function convertToDatabaseValue($value)
{
if ($value) {
Expand All @@ -23,6 +31,11 @@ public function convertToDatabaseValue($value)
return null;
}

/**
* @param string $value
*
* @return string|Currency
*/
public function convertToPHPValue($value)
{
if ($value === null || $value instanceof Currency) {
Expand Down
11 changes: 6 additions & 5 deletions src/View/Helper/MoneyFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
class MoneyFormat extends AbstractHelper
{
/**
* @param Money $money
* @param bool $showDecimals
* @param string $locale
* @param string $pattern
* @param Money $money
* @param bool $showDecimals
* @param string $locale
* @param string $pattern
*
* @return string
*/
public function __invoke(Money $money, $showDecimals = null, $locale = null, $pattern = null)
{
$currencyFormat = $this->getView()->plugin('currencyFormat');

return $currencyFormat($money->getAmount() / 100, $money->getCurrency(), $showDecimals, $locale, $pattern);
}
}
6 changes: 3 additions & 3 deletions test/Form/Element/Factory/CurrencySelectFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class CurrencySelectFactoryTest extends TestCase
'money' => [
'currencies' => [
'BRL' => 'Brazilian Real',
'SAD' => 'Sad Asteka'
]
]
'SAD' => 'Sad Asteka',
],
],
];

public function setUp()
Expand Down
40 changes: 20 additions & 20 deletions test/Form/FormIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Zend\Stdlib\Hydrator\ObjectProperty;

/**
* Test to see if Form returns a valid object on getData
* Test to see if Form returns a valid object on getData.
*
* @author Fábio Carneiro <[email protected]>
* @license MIT
Expand All @@ -41,7 +41,7 @@ public function testElementDirectlyInTheForm()

$form = new Form();
$form->setHydrator(new ObjectProperty());
$form->setObject(new StdClass);
$form->setObject(new StdClass());
$form->add($element, ['name' => 'money']);

$this->assertFalse($form->setData([])->isValid());
Expand All @@ -50,24 +50,24 @@ public function testElementDirectlyInTheForm()

$data = [
'money' => [
'amount' => "500.20",
'currency' => "BRL"
]
'amount' => '500.20',
'currency' => 'BRL',
],
];

$form->setData($data);

$this->assertTrue($form->isValid());

$amountValue = $form->get('money')->get('amount')->getValue();
$amountValue = $form->get('money')->get('amount')->getValue();
$currencyValue = $form->get('money')->get('currency')->getValue();
$object = $form->getData()->money;
$object = $form->getData()->money;

$this->assertSame("500.20", $amountValue);
$this->assertSame("BRL", $currencyValue);
$this->assertSame('500.20', $amountValue);
$this->assertSame('BRL', $currencyValue);
$this->assertInstanceOf(Money::class, $object);
$this->assertSame(50020, $object->getAmount());
$this->assertSame("BRL", $object->getCurrency()->getName());
$this->assertSame('BRL', $object->getCurrency()->getName());
}

public function testElementInAFieldsetForSomeModel()
Expand All @@ -84,29 +84,29 @@ public function testElementInAFieldsetForSomeModel()
$form->add($fieldset);

// todo: can't load this
$form->bind(new HasMoneyPropertyModel);
$form->bind(new HasMoneyPropertyModel());

$data = [
'hasMoneyElementFieldset' => [
'price' => [
'amount' => "500.25",
'currency' => "BRL"
]
]
'amount' => '500.25',
'currency' => 'BRL',
],
],
];

$form->setData($data);
$this->assertTrue($form->isValid());

$amountValue = $form->get('hasMoneyElementFieldset')->get('price')->get('amount')->getValue();
$amountValue = $form->get('hasMoneyElementFieldset')->get('price')->get('amount')->getValue();
$currencyValue = $form->get('hasMoneyElementFieldset')->get('price')->get('currency')->getValue();
$object = $form->getData();
$object = $form->getData();

$this->assertSame("500.25", $amountValue);
$this->assertSame("BRL", $currencyValue);
$this->assertSame('500.25', $amountValue);
$this->assertSame('BRL', $currencyValue);
$this->assertInstanceOf(Money::class, $object->getPrice());
$this->assertSame(50025, $object->getPrice()->getAmount());
$this->assertSame("BRL", $object->getPrice()->getCurrency()->getName());
$this->assertSame('BRL', $object->getPrice()->getCurrency()->getName());
}

/**
Expand Down
Loading

0 comments on commit df26ab0

Please sign in to comment.