From 879a7b7f8a93836819769b7de3b9b81f83997850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Sat, 25 Mar 2017 10:04:48 +0100 Subject: [PATCH] PHP CS Fixer 2.0 --- .gitignore | 2 + .php_cs | 41 +++--- Core/FieldType/Birthday/Type.php | 135 +++++++++--------- Core/FieldType/Birthday/Value.php | 2 +- .../Content/FieldValue/Converter/Birthday.php | 3 +- .../NetgenBirthdayExtension.php | 8 +- Form/FieldTypeHandler/Birthday.php | 42 +++--- Tests/Core/FieldType/Birthday/ValueTest.php | 2 +- .../FieldValue/Converter/BirthdayTest.php | 2 +- 9 files changed, 123 insertions(+), 114 deletions(-) diff --git a/.gitignore b/.gitignore index 3d0b430..544ee68 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .php_cs.cache +composer.lock +vendor diff --git a/.php_cs b/.php_cs index a25cf15..d010ce7 100644 --- a/.php_cs +++ b/.php_cs @@ -1,24 +1,29 @@ setUsingLinter(false) - ->setUsingCache(true) - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - ->fixers([ - 'concat_with_spaces', - '-concat_without_spaces', - '-empty_return', - '-phpdoc_params', - '-phpdoc_separation', - '-phpdoc_to_comment', - '-spaces_cast', - '-blankline_after_open_tag', +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => array('syntax' => 'long'), + 'combine_consecutive_unsets' => true, + 'concat_space' => ['spacing' => 'one'], + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_align' => false, + 'phpdoc_order' => true, + 'phpdoc_no_alias_tag' => false, + 'psr4' => true, + 'semicolon_after_instruction' => true, + 'strict_comparison' => true, + 'strict_param' => true, ]) - ->finder( - Symfony\CS\Finder\DefaultFinder::create() + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude(['vendor']) ->in(__DIR__) - ->exclude([ - 'vendor', - ]) ) ; diff --git a/Core/FieldType/Birthday/Type.php b/Core/FieldType/Birthday/Type.php index c7340dc..4b85c9b 100644 --- a/Core/FieldType/Birthday/Type.php +++ b/Core/FieldType/Birthday/Type.php @@ -2,12 +2,12 @@ namespace Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday; +use DateTime; use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType; use eZ\Publish\Core\FieldType\FieldType; +use eZ\Publish\Core\FieldType\ValidationError; use eZ\Publish\Core\FieldType\Value as BaseValue; use eZ\Publish\SPI\FieldType\Value as SPIValue; -use eZ\Publish\Core\FieldType\ValidationError; -use DateTime; class Type extends FieldType { @@ -59,7 +59,7 @@ public function getFieldTypeIdentifier() */ public function getName(SPIValue $value) { - return (string)$value; + return (string) $value; } /** @@ -97,69 +97,7 @@ public function fromHash($hash) */ public function toHash(SPIValue $value) { - return (string)$value; - } - - /** - * Inspects given $inputValue and potentially converts it into a dedicated value object. - * - * If given $inputValue could not be converted or is already an instance of dedicate value object, - * the method should simply return it. - * - * @param mixed $inputValue - * - * @return mixed The potentially converted input value - */ - protected function createValueFromInput($inputValue) - { - if ($inputValue instanceof DateTime || is_string($inputValue)) { - return new Value($inputValue); - } - - return $inputValue; - } - - /** - * Throws an exception if value structure is not of expected format. - * - * Note that this does not include validation after the rules - * from validators, but only plausibility checks for the general data - * format. - * - * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the value does not match the expected structure - * - * @param \eZ\Publish\Core\FieldType\Value|\Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday\Value $value - */ - protected function checkValueStructure(BaseValue $value) - { - if (!$value->date instanceof DateTime) { - throw new InvalidArgumentType( - '$value->date', - 'DateTime', - $value->date - ); - } - } - - /** - * Returns information for FieldValue->$sortKey relevant to the field type. - * - * Return value is mixed. It should be something which is sensible for - * sorting. - * - * It is up to the persistence implementation to handle those values. - * Common string and integer values are safe. - * - * For the legacy storage it is up to the field converters to set this - * value in either sort_key_string or sort_key_int. - * - * @param \eZ\Publish\Core\FieldType\Value $value - * - * @return mixed - */ - protected function getSortInfo(BaseValue $value) - { - return $this->getName($value); + return (string) $value; } /** @@ -192,7 +130,7 @@ public function validateFieldSettings($fieldSettings) switch ($name) { case 'defaultValue': - if (!is_integer($value)) { + if (!is_int($value)) { $validationErrors[] = new ValidationError( "Setting '%setting%' value must be of integer type", null, @@ -228,4 +166,67 @@ public function isSearchable() { return true; } + + /** + * Inspects given $inputValue and potentially converts it into a dedicated value object. + * + * If given $inputValue could not be converted or is already an instance of dedicate value object, + * the method should simply return it. + * + * @param mixed $inputValue + * + * @return mixed The potentially converted input value + */ + protected function createValueFromInput($inputValue) + { + if ($inputValue instanceof DateTime || is_string($inputValue)) { + return new Value($inputValue); + } + + return $inputValue; + } + + /** + * Throws an exception if value structure is not of expected format. + * + * Note that this does not include validation after the rules + * from validators, but only plausibility checks for the general data + * format. + * + * + * @param \eZ\Publish\Core\FieldType\Value|\Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday\Value $value + * + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the value does not match the expected structure + */ + protected function checkValueStructure(BaseValue $value) + { + if (!$value->date instanceof DateTime) { + throw new InvalidArgumentType( + '$value->date', + 'DateTime', + $value->date + ); + } + } + + /** + * Returns information for FieldValue->$sortKey relevant to the field type. + * + * Return value is mixed. It should be something which is sensible for + * sorting. + * + * It is up to the persistence implementation to handle those values. + * Common string and integer values are safe. + * + * For the legacy storage it is up to the field converters to set this + * value in either sort_key_string or sort_key_int. + * + * @param \eZ\Publish\Core\FieldType\Value $value + * + * @return mixed + */ + protected function getSortInfo(BaseValue $value) + { + return $this->getName($value); + } } diff --git a/Core/FieldType/Birthday/Value.php b/Core/FieldType/Birthday/Value.php index 15712f7..836e7b1 100644 --- a/Core/FieldType/Birthday/Value.php +++ b/Core/FieldType/Birthday/Value.php @@ -2,8 +2,8 @@ namespace Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday; -use eZ\Publish\Core\FieldType\Value as BaseValue; use DateTime; +use eZ\Publish\Core\FieldType\Value as BaseValue; class Value extends BaseValue { diff --git a/Core/Persistence/Legacy/Content/FieldValue/Converter/Birthday.php b/Core/Persistence/Legacy/Content/FieldValue/Converter/Birthday.php index 8aadfdd..99cae3e 100644 --- a/Core/Persistence/Legacy/Content/FieldValue/Converter/Birthday.php +++ b/Core/Persistence/Legacy/Content/FieldValue/Converter/Birthday.php @@ -1,4 +1,5 @@ fieldTypeConstraints->fieldSettings = new FieldSettings( array( - 'defaultValue' => (int)$storageDef->dataText1, + 'defaultValue' => (int) $storageDef->dataText1, ) ); } diff --git a/DependencyInjection/NetgenBirthdayExtension.php b/DependencyInjection/NetgenBirthdayExtension.php index ecdac04..2b4910b 100644 --- a/DependencyInjection/NetgenBirthdayExtension.php +++ b/DependencyInjection/NetgenBirthdayExtension.php @@ -2,12 +2,12 @@ namespace Netgen\Bundle\BirthdayBundle\DependencyInjection; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\DependencyInjection\Loader; -use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; +use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\Yaml\Yaml; class NetgenBirthdayExtension extends Extension implements PrependExtensionInterface diff --git a/Form/FieldTypeHandler/Birthday.php b/Form/FieldTypeHandler/Birthday.php index 8840ae9..e15b838 100644 --- a/Form/FieldTypeHandler/Birthday.php +++ b/Form/FieldTypeHandler/Birthday.php @@ -2,37 +2,19 @@ namespace Netgen\Bundle\BirthdayBundle\Form\FieldTypeHandler; +use eZ\Publish\API\Repository\Values\Content\Content; +use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; use eZ\Publish\SPI\FieldType\Value; +use Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday as BirthdayValue; use Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler; use Symfony\Component\Form\FormBuilderInterface; -use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; -use eZ\Publish\API\Repository\Values\Content\Content; use Symfony\Component\Validator\Constraints as Assert; -use Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday as BirthdayValue; /** * Class Birthday. */ class Birthday extends FieldTypeHandler { - /** - * {@inheritdoc} - */ - protected function buildFieldForm( - FormBuilderInterface $formBuilder, - FieldDefinition $fieldDefinition, - $languageCode, - Content $content = null - ) { - $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); - - $options['input'] = 'datetime'; - $options['widget'] = 'choice'; - $options['constraints'][] = new Assert\Date(); - - $formBuilder->add($fieldDefinition->identifier, 'birthday', $options); - } - /** * {@inheritdoc} */ @@ -54,4 +36,22 @@ public function convertFieldValueFromForm($data) return new BirthdayValue\Value($data); } + + /** + * {@inheritdoc} + */ + protected function buildFieldForm( + FormBuilderInterface $formBuilder, + FieldDefinition $fieldDefinition, + $languageCode, + Content $content = null + ) { + $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); + + $options['input'] = 'datetime'; + $options['widget'] = 'choice'; + $options['constraints'][] = new Assert\Date(); + + $formBuilder->add($fieldDefinition->identifier, 'birthday', $options); + } } diff --git a/Tests/Core/FieldType/Birthday/ValueTest.php b/Tests/Core/FieldType/Birthday/ValueTest.php index 53a55cc..2261fd1 100644 --- a/Tests/Core/FieldType/Birthday/ValueTest.php +++ b/Tests/Core/FieldType/Birthday/ValueTest.php @@ -2,8 +2,8 @@ namespace Netgen\Bundle\BirthdayBundle\Tests\Core\FieldType\Birthday; -use Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday\Value; use eZ\Publish\Core\FieldType\Value as BaseValue; +use Netgen\Bundle\BirthdayBundle\Core\FieldType\Birthday\Value; class ValueTest extends \PHPUnit_Framework_TestCase { diff --git a/Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/BirthdayTest.php b/Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/BirthdayTest.php index f974845..066e7aa 100644 --- a/Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/BirthdayTest.php +++ b/Tests/Core/Persistence/Legacy/Content/FieldValue/Converter/BirthdayTest.php @@ -5,8 +5,8 @@ use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter; use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition; use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue; -use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition; use eZ\Publish\SPI\Persistence\Content\FieldValue; +use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition; use Netgen\Bundle\BirthdayBundle\Core\Persistence\Legacy\Content\FieldValue\Converter\Birthday; class BirthdayTest extends \PHPUnit_Framework_TestCase