Skip to content

Commit

Permalink
PHP CS Fixer 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Mar 25, 2017
1 parent c2c09db commit 879a7b7
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 114 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
.php_cs.cache
composer.lock
vendor
41 changes: 23 additions & 18 deletions .php_cs
@@ -1,24 +1,29 @@
<?php

return Symfony\CS\Config\Config::create()
->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',
])
)
;
135 changes: 68 additions & 67 deletions Core/FieldType/Birthday/Type.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public function getFieldTypeIdentifier()
*/
public function getName(SPIValue $value)
{
return (string)$value;
return (string) $value;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion Core/FieldType/Birthday/Value.php
Expand Up @@ -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
{
Expand Down
@@ -1,4 +1,5 @@
<?php

namespace Netgen\Bundle\BirthdayBundle\Core\Persistence\Legacy\Content\FieldValue\Converter;

use eZ\Publish\Core\FieldType\FieldSettings;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin
{
$fieldDef->fieldTypeConstraints->fieldSettings = new FieldSettings(
array(
'defaultValue' => (int)$storageDef->dataText1,
'defaultValue' => (int) $storageDef->dataText1,
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/NetgenBirthdayExtension.php
Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions Form/FieldTypeHandler/Birthday.php
Expand Up @@ -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}
*/
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion Tests/Core/FieldType/Birthday/ValueTest.php
Expand Up @@ -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
{
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 879a7b7

Please sign in to comment.