[Form] Fixed YODA issues
This commit is contained in:
parent
600cec746a
commit
8dc78bd0c9
@ -20,7 +20,7 @@ use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
/**
|
||||
* Base class for choice list implementations.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @author Bernhard Schussek <bschussek@gmail.<com>
|
||||
*/
|
||||
class ChoiceList implements ChoiceListInterface
|
||||
{
|
||||
@ -530,7 +530,11 @@ class ChoiceList implements ChoiceListInterface
|
||||
*/
|
||||
protected function fixValues(array $values)
|
||||
{
|
||||
return array_map(array($this, 'fixValue'), $values);
|
||||
foreach ($values as $i => $value) {
|
||||
$values[$i] = $this->fixValue($value);
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -560,7 +564,11 @@ class ChoiceList implements ChoiceListInterface
|
||||
*/
|
||||
protected function fixIndices(array $indices)
|
||||
{
|
||||
return array_map(array($this, 'fixIndex'), $indices);
|
||||
foreach ($indices as $i => $index) {
|
||||
$indices[$i] = $this->fixIndex($index);
|
||||
}
|
||||
|
||||
return $indices;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ class ObjectChoiceList extends ChoiceList
|
||||
throw new UnexpectedTypeException($choices, 'array or \Traversable');
|
||||
}
|
||||
|
||||
if ($this->groupPath !== null) {
|
||||
if (null !== $this->groupPath) {
|
||||
$groupedChoices = array();
|
||||
|
||||
foreach ($choices as $i => $choice) {
|
||||
|
@ -59,7 +59,7 @@ class PropertyPathMapper implements DataMapperInterface
|
||||
public function mapDataToForm($data, FormInterface $form)
|
||||
{
|
||||
if (!empty($data)) {
|
||||
if ($form->getAttribute('property_path') !== null) {
|
||||
if (null !== $form->getAttribute('property_path')) {
|
||||
$form->setData($form->getAttribute('property_path')->getValue($data));
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,7 @@ class PropertyPathMapper implements DataMapperInterface
|
||||
|
||||
public function mapFormToData(FormInterface $form, &$data)
|
||||
{
|
||||
if ($form->getAttribute('property_path') !== null && $form->isSynchronized()) {
|
||||
if (null !== $form->getAttribute('property_path') && $form->isSynchronized()) {
|
||||
$propertyPath = $form->getAttribute('property_path');
|
||||
|
||||
// If the data is identical to the value in $data, we are
|
||||
|
@ -46,18 +46,18 @@ class ChoiceToValueTransformer implements DataTransformerInterface
|
||||
|
||||
// These are now valid ChoiceList values, so we can return null
|
||||
// right away
|
||||
if ($value === '' || $value === null) {
|
||||
if ('' === $value || null === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$choices = $this->choiceList->getChoicesForValues(array($value));
|
||||
|
||||
if (count($choices) !== 1) {
|
||||
if (1 !== count($choices)) {
|
||||
throw new TransformationFailedException('The choice "' . $value . '" does not exist or is not unique');
|
||||
}
|
||||
|
||||
$choice = current($choices);
|
||||
|
||||
return $choice === '' ? null : $choice;
|
||||
return '' === $choice ? null : $choice;
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
||||
throw new UnexpectedTypeException($value, 'array');
|
||||
}
|
||||
|
||||
if (implode('', $value) === '') {
|
||||
if ('' === implode('', $value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
||||
{
|
||||
$formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
|
||||
|
||||
if ($this->precision !== null) {
|
||||
if (null !== $this->precision) {
|
||||
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision);
|
||||
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class FixRadioInputListener implements EventSubscriberInterface
|
||||
$value = $event->getData();
|
||||
$index = current($this->choiceList->getIndicesForValues(array($value)));
|
||||
|
||||
$event->setData($index !== false ? array($index => $value) : array());
|
||||
$event->setData(false !== $index ? array($index => $value) : array());
|
||||
}
|
||||
|
||||
static public function getSubscribedEvents()
|
||||
|
@ -45,7 +45,7 @@ class DateTimeType extends AbstractType
|
||||
throw new FormException(sprintf('Options "date_widget" and "time_widget" need to be identical. Used: "date_widget" = "%s" and "time_widget" = "%s".', $options['date_widget'] ?: 'choice', $options['time_widget'] ?: 'choice'));
|
||||
}
|
||||
|
||||
if ($options['widget'] === 'single_text') {
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
|
||||
} else {
|
||||
// Only pass a subset of the options to children
|
||||
@ -105,15 +105,15 @@ class DateTimeType extends AbstractType
|
||||
;
|
||||
}
|
||||
|
||||
if ($options['input'] === 'string') {
|
||||
if ('string' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)
|
||||
));
|
||||
} elseif ($options['input'] === 'timestamp') {
|
||||
} elseif ('timestamp' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])
|
||||
));
|
||||
} elseif ($options['input'] === 'array') {
|
||||
} elseif ('array' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], $parts)
|
||||
));
|
||||
@ -200,7 +200,7 @@ class DateTimeType extends AbstractType
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
{
|
||||
return $options['widget'] === 'single_text' ? 'field' : 'form';
|
||||
return 'single_text' === $options['widget'] ? 'field' : 'form';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,12 +63,12 @@ class DateType extends AbstractType
|
||||
$pattern
|
||||
);
|
||||
|
||||
if ($options['widget'] === 'single_text') {
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
|
||||
} else {
|
||||
$yearOptions = $monthOptions = $dayOptions = array();
|
||||
|
||||
if ($options['widget'] === 'choice') {
|
||||
if ('choice' === $options['widget']) {
|
||||
if (is_array($options['empty_value'])) {
|
||||
$options['empty_value'] = array_merge(array('year' => null, 'month' => null, 'day' => null), $options['empty_value']);
|
||||
} else {
|
||||
@ -123,15 +123,15 @@ class DateType extends AbstractType
|
||||
;
|
||||
}
|
||||
|
||||
if ($options['input'] === 'string') {
|
||||
if ('string' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')
|
||||
));
|
||||
} elseif ($options['input'] === 'timestamp') {
|
||||
} elseif ('timestamp' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])
|
||||
));
|
||||
} elseif ($options['input'] === 'array') {
|
||||
} elseif ('array' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))
|
||||
));
|
||||
@ -212,7 +212,7 @@ class DateType extends AbstractType
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
{
|
||||
return $options['widget'] === 'single_text' ? 'field' : 'form';
|
||||
return 'single_text' === $options['widget'] ? 'field' : 'form';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,12 +35,12 @@ class TimeType extends AbstractType
|
||||
$parts[] = 'second';
|
||||
}
|
||||
|
||||
if ($options['widget'] === 'single_text') {
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
|
||||
} else {
|
||||
$hourOptions = $minuteOptions = $secondOptions = array();
|
||||
|
||||
if ($options['widget'] === 'choice') {
|
||||
if ('choice' === $options['widget']) {
|
||||
if (is_array($options['empty_value'])) {
|
||||
$options['empty_value'] = array_merge(array('hour' => null, 'minute' => null, 'second' => null), $options['empty_value']);
|
||||
} else {
|
||||
@ -103,18 +103,18 @@ class TimeType extends AbstractType
|
||||
$builder->add('second', $options['widget'], $secondOptions);
|
||||
}
|
||||
|
||||
$builder->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, $options['widget'] === 'text'));
|
||||
$builder->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, 'text' === $options['widget']));
|
||||
}
|
||||
|
||||
if ($options['input'] === 'string') {
|
||||
if ('string' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)
|
||||
));
|
||||
} elseif ($options['input'] === 'timestamp') {
|
||||
} elseif ('timestamp' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])
|
||||
));
|
||||
} elseif ($options['input'] === 'array') {
|
||||
} elseif ('array' === $options['input']) {
|
||||
$builder->appendNormTransformer(new ReversedTransformer(
|
||||
new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], $parts)
|
||||
));
|
||||
@ -184,7 +184,7 @@ class TimeType extends AbstractType
|
||||
*/
|
||||
public function getParent(array $options)
|
||||
{
|
||||
return $options['widget'] === 'single_text' ? 'field' : 'form';
|
||||
return 'single_text' === $options['widget'] ? 'field' : 'form';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,7 +229,7 @@ class DelegatingValidator implements FormValidatorInterface
|
||||
|
||||
$nestedNamePath = $namePath.'.'.$child->getName();
|
||||
|
||||
if (strpos($path, '[') === 0) {
|
||||
if (0 === strpos($path, '[')) {
|
||||
$nestedDataPaths = array($dataPath.$path);
|
||||
} else {
|
||||
$nestedDataPaths = array($dataPath.'.'.$path);
|
||||
|
@ -1098,6 +1098,6 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*/
|
||||
static public function isValidName($name)
|
||||
{
|
||||
return $name === '' || preg_match('/^[a-zA-Z0-9_][a-zA-Z0-9_\-:]*$/D', $name);
|
||||
return '' === $name || preg_match('/^[a-zA-Z0-9_][a-zA-Z0-9_\-:]*$/D', $name);
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class PropertyPath implements \IteratorAggregate
|
||||
$pattern = '/^(([^\.\[]+)|\[([^\]]+)\])(.*)/';
|
||||
|
||||
while (preg_match($pattern, $remaining, $matches)) {
|
||||
if ($matches[2] !== '') {
|
||||
if ('' !== $matches[2]) {
|
||||
$this->elements[] = $matches[2];
|
||||
$this->isIndex[] = false;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user