From 23f76f096883cf8538732a0784abca6f226537fe Mon Sep 17 00:00:00 2001 From: Daniel Gimenes Date: Mon, 20 Jun 2016 11:08:31 -0300 Subject: [PATCH 1/2] Update dependency constraints --- composer.json | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 19f8578..bb02145 100644 --- a/composer.json +++ b/composer.json @@ -17,26 +17,27 @@ } ], "require-dev": { - "phpunit/phpunit": "~4.4", - "fabpot/php-cs-fixer": "dev-master", - "doctrine/dbal": "~2.5", - "doctrine/mongodb-odm": "1.0.*@dev" + "phpunit/phpunit": "^4.4", + "friendsofphp/php-cs-fixer": "^1.11", + "doctrine/dbal": "^2.5", + "doctrine/mongodb-odm": "^1.0" }, "require": { - "php": ">=5.5", - "doctrine/doctrine-module": "~0.8 || ~1.0", - "zendframework/zend-form": "~2.3", - "zendframework/zend-filter": "~2.3", - "zendframework/zend-validator": "~2.3", - "zendframework/zend-view": "~2.3", - "zendframework/zend-servicemanager": "~2.3", - "zendframework/zend-modulemanager": "~2.3", - "zendframework/zend-i18n": "~2.3", - "mathiasverraes/money": "1.2.*" + "php": "^5.5 || ^7.0", + "doctrine/doctrine-module": "^0.8 || ^1.0", + "zendframework/zend-form": "^2.3", + "zendframework/zend-filter": "^2.3", + "zendframework/zend-validator": "^2.3", + "zendframework/zend-view": "^2.3", + "zendframework/zend-servicemanager": "^2.3", + "zendframework/zend-modulemanager": "^2.3", + "zendframework/zend-i18n": "^2.3", + "mathiasverraes/money": "^1.2" }, "suggest": { - "doctrine/dbal": "2.5.*", - "doctrine/mongodb-odm": "1.0.*@dev" + "doctrine/dbal": "^2.5", + "doctrine/mongodb-odm": "^1.0", + "doctrine/orm": "^2.5" }, "autoload": { "psr-4": { From df26ab0611bba43e2e162539509a59e17ed4e2c1 Mon Sep 17 00:00:00 2001 From: Daniel Gimenes Date: Mon, 20 Jun 2016 11:42:13 -0300 Subject: [PATCH 2/2] CS Fixes --- .travis.yml | 3 +- src/DBAL/Types/CurrencyType.php | 7 ++-- src/Filter/AmountFilter.php | 6 +-- .../Element/Factory/CurrencySelectFactory.php | 3 +- src/Form/MoneyFieldset.php | 14 +++---- src/Hydrator/MoneyHydrator.php | 10 ++--- src/InputFilter/MoneyInputFilter.php | 14 +++---- src/Module.php | 4 +- src/ODM/MongoDB/Types/CurrencyType.php | 13 ++++++ src/View/Helper/MoneyFormat.php | 11 ++--- .../Factory/CurrencySelectFactoryTest.php | 6 +-- test/Form/FormIntegrationTest.php | 40 +++++++++---------- test/Form/MoneyFieldsetTest.php | 11 ++--- test/Hydrator/MoneyHydratorTest.php | 3 -- .../TestAsset/Model/HasMoneyPropertyModel.php | 2 +- 15 files changed, 78 insertions(+), 69 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc8462f..5003ee3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/src/DBAL/Types/CurrencyType.php b/src/DBAL/Types/CurrencyType.php index 9edbabc..9b100c9 100644 --- a/src/DBAL/Types/CurrencyType.php +++ b/src/DBAL/Types/CurrencyType.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Types\StringType; use Money\Currency; -use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -14,9 +13,9 @@ class CurrencyType extends StringType { const NAME = 'currency'; - + /** - * {@inheritDoc} + * {@inheritdoc} */ public function getName() { @@ -24,7 +23,7 @@ public function getName() } /** - * {@inheritDoc} + * {@inheritdoc} */ public function convertToPHPValue($value, AbstractPlatform $platform) { diff --git a/src/Filter/AmountFilter.php b/src/Filter/AmountFilter.php index b3a9c65..816ff9b 100644 --- a/src/Filter/AmountFilter.php +++ b/src/Filter/AmountFilter.php @@ -5,7 +5,6 @@ use Money\InvalidArgumentException; use Money\Money; use Zend\Filter\AbstractFilter; -use Zend\Filter\Exception; /** * @author Gabriel Schmitt @@ -14,10 +13,11 @@ class AmountFilter extends AbstractFilter { /** - * {@inheritDoc} + * {@inheritdoc} * * @throws InvalidArgumentException - * @return int + * + * @return int|null */ public function filter($value) { diff --git a/src/Form/Element/Factory/CurrencySelectFactory.php b/src/Form/Element/Factory/CurrencySelectFactory.php index 6e1f32f..055b26e 100644 --- a/src/Form/Element/Factory/CurrencySelectFactory.php +++ b/src/Form/Element/Factory/CurrencySelectFactory.php @@ -14,6 +14,7 @@ class CurrencySelectFactory { /** * @param FormElementManager $formElementManager + * * @return CurrencySelect */ public function __invoke(FormElementManager $formElementManager) @@ -21,7 +22,7 @@ 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.'); } diff --git a/src/Form/MoneyFieldset.php b/src/Form/MoneyFieldset.php index 65aec9c..b2a2091 100644 --- a/src/Form/MoneyFieldset.php +++ b/src/Form/MoneyFieldset.php @@ -9,7 +9,7 @@ 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 * @license MIT @@ -17,7 +17,7 @@ class MoneyFieldset extends Fieldset implements InputFilterProviderInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public function init() { @@ -25,24 +25,24 @@ public function init() '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() { diff --git a/src/Hydrator/MoneyHydrator.php b/src/Hydrator/MoneyHydrator.php index 7cf2fd1..d70199b 100644 --- a/src/Hydrator/MoneyHydrator.php +++ b/src/Hydrator/MoneyHydrator.php @@ -7,7 +7,7 @@ use Money\Currency; /** - * Hydrator for Money object + * Hydrator for Money object. * * @author Fábio Carneiro * @license MIT @@ -15,20 +15,20 @@ 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) { diff --git a/src/InputFilter/MoneyInputFilter.php b/src/InputFilter/MoneyInputFilter.php index 3ae73df..9d8ea38 100644 --- a/src/InputFilter/MoneyInputFilter.php +++ b/src/InputFilter/MoneyInputFilter.php @@ -14,7 +14,7 @@ class MoneyInputFilter extends InputFilter { /** - * {@inheritDoc} + * {@inheritdoc} */ public function init() { @@ -22,22 +22,22 @@ public function init() '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], + ], ]); } } diff --git a/src/Module.php b/src/Module.php index a0b6b0e..d86adaa 100644 --- a/src/Module.php +++ b/src/Module.php @@ -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'; } } diff --git a/src/ODM/MongoDB/Types/CurrencyType.php b/src/ODM/MongoDB/Types/CurrencyType.php index ccd4018..175a8f9 100644 --- a/src/ODM/MongoDB/Types/CurrencyType.php +++ b/src/ODM/MongoDB/Types/CurrencyType.php @@ -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) { @@ -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) { diff --git a/src/View/Helper/MoneyFormat.php b/src/View/Helper/MoneyFormat.php index 9560152..2d8a1f9 100644 --- a/src/View/Helper/MoneyFormat.php +++ b/src/View/Helper/MoneyFormat.php @@ -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); } } diff --git a/test/Form/Element/Factory/CurrencySelectFactoryTest.php b/test/Form/Element/Factory/CurrencySelectFactoryTest.php index 9ca4da3..e25349c 100644 --- a/test/Form/Element/Factory/CurrencySelectFactoryTest.php +++ b/test/Form/Element/Factory/CurrencySelectFactoryTest.php @@ -24,9 +24,9 @@ class CurrencySelectFactoryTest extends TestCase 'money' => [ 'currencies' => [ 'BRL' => 'Brazilian Real', - 'SAD' => 'Sad Asteka' - ] - ] + 'SAD' => 'Sad Asteka', + ], + ], ]; public function setUp() diff --git a/test/Form/FormIntegrationTest.php b/test/Form/FormIntegrationTest.php index 875ebee..d28be88 100644 --- a/test/Form/FormIntegrationTest.php +++ b/test/Form/FormIntegrationTest.php @@ -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 * @license MIT @@ -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()); @@ -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() @@ -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()); } /** diff --git a/test/Form/MoneyFieldsetTest.php b/test/Form/MoneyFieldsetTest.php index 2498618..1caf118 100644 --- a/test/Form/MoneyFieldsetTest.php +++ b/test/Form/MoneyFieldsetTest.php @@ -5,15 +5,12 @@ use Money\Currency; use Money\Money; use PHPUnit_Framework_TestCase as TestCase; -use Zend\Form\Element\Number; -use Zend\Form\Factory; use Zend\Form\FormElementManager; -use ZFBrasil\DoctrineMoneyModule\Form\Element\CurrencySelect; use ZFBrasil\DoctrineMoneyModule\Form\Factory\MoneyFieldsetFactory; use ZFBrasil\DoctrineMoneyModule\Form\MoneyFieldset; /** - * Description of MoneyFieldsetTest + * Description of MoneyFieldsetTest. * * @author Fábio Carneiro * @license MIT @@ -26,7 +23,7 @@ public function testCanHydrateMoneyWithInteger() $fieldset->bindValues([ 'amount' => 500, - 'currency' => 'BRL' + 'currency' => 'BRL', ]); $this->assertInstanceOf(Money::class, $fieldset->getObject()); } @@ -47,8 +44,8 @@ public function testCanHydrateMoneyWithString() $fieldset = $this->getMoneyFieldset(); $fieldset->bindValues([ - 'amount' => "500", - 'currency' => 'BRL' + 'amount' => '500', + 'currency' => 'BRL', ]); $this->assertInstanceOf(Money::class, $fieldset->getObject()); diff --git a/test/Hydrator/MoneyHydratorTest.php b/test/Hydrator/MoneyHydratorTest.php index 9d1b942..18167cd 100644 --- a/test/Hydrator/MoneyHydratorTest.php +++ b/test/Hydrator/MoneyHydratorTest.php @@ -4,9 +4,6 @@ use Money\Currency; use PHPUnit_Framework_TestCase as TestCase; -use Zend\Form\FormElementManager; -use ZFBrasil\DoctrineMoneyModule\Form\Factory\MoneyFieldsetFactory; -use ZFBrasil\DoctrineMoneyModule\Form\MoneyFieldset; use Money\Money; use ZFBrasil\DoctrineMoneyModule\Hydrator\MoneyHydrator; diff --git a/test/TestAsset/Model/HasMoneyPropertyModel.php b/test/TestAsset/Model/HasMoneyPropertyModel.php index d58ff86..4b7c951 100644 --- a/test/TestAsset/Model/HasMoneyPropertyModel.php +++ b/test/TestAsset/Model/HasMoneyPropertyModel.php @@ -5,7 +5,7 @@ use Money\Money; /** - * Model for testing purposes + * Model for testing purposes. * * @author Fábio Carneiro * @license MIT