Permalink
Browse files

[Form] Fixed issues mentioned in the PR comments

  • Loading branch information...
1 parent 66298c3 commit 3bc32dae5fc633cd982f8eac8255a8fb335a5a64 @webmozart webmozart committed May 20, 2012
View
@@ -42,7 +42,7 @@ public function __construct(\Closure $transform, \Closure $reverseTransform)
*
* @param mixed $data The value in the original representation
*
- * @return mixed The value in the transformed representation
+ * @return mixed The value in the transformed representation
*
* @throws UnexpectedTypeException when the argument is not a string
* @throws TransformationFailedException when the transformation fails
@@ -58,7 +58,7 @@ public function transform($data)
*
* @param mixed $data The value in the transformed representation
*
- * @return mixed The value in the original representation
+ * @return mixed The value in the original representation
*
* @throws UnexpectedTypeException when the argument is not of the expected type
* @throws TransformationFailedException when the transformation fails
@@ -41,7 +41,7 @@
*
* @param mixed $value The value in the original representation
*
- * @return mixed The value in the transformed representation
+ * @return mixed The value in the transformed representation
*
* @throws UnexpectedTypeException when the argument is not a string
* @throws TransformationFailedException when the transformation fails
@@ -68,7 +68,7 @@ function transform($value);
*
* @param mixed $value The value in the transformed representation
*
- * @return mixed The value in the original representation
+ * @return mixed The value in the original representation
*
* @throws UnexpectedTypeException when the argument is not of the expected type
* @throws TransformationFailedException when the transformation fails
@@ -43,7 +43,7 @@ public function __construct($trueValue)
*
* @param Boolean $value Boolean value.
*
- * @return string String value.
+ * @return string String value.
*
* @throws UnexpectedTypeException if the given value is not a Boolean
*/
@@ -65,7 +65,7 @@ public function transform($value)
*
* @param string $value String value.
*
- * @return Boolean Boolean value.
+ * @return Boolean Boolean value.
*
* @throws UnexpectedTypeException if the given value is not a string
*/
@@ -46,7 +46,7 @@ public function __construct(array $transformers)
*
* @param mixed $value The original value
*
- * @return mixed The transformed value
+ * @return mixed The transformed value
*
* @throws Symfony\Component\Form\Exception\TransformationFailedException
* @throws Symfony\Component\Form\Exception\UnexpectedTypeException
@@ -71,7 +71,7 @@ public function transform($value)
*
* @param mixed $value The transformed value
*
- * @return mixed The reverse-transformed value
+ * @return mixed The reverse-transformed value
*
* @throws Symfony\Component\Form\Exception\TransformationFailedException
* @throws Symfony\Component\Form\Exception\UnexpectedTypeException
@@ -53,7 +53,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, array
*
* @param DateTime $dateTime Normalized date.
*
- * @return array Localized date.
+ * @return array Localized date.
*
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
* @throws TransformationFailedException if the output timezone is not supported
@@ -108,7 +108,7 @@ public function transform($dateTime)
*
* @param array $value Localized date
*
- * @return DateTime Normalized date
+ * @return DateTime Normalized date
*
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the value could not bet transformed
@@ -48,7 +48,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, $form
*
* @param DateTime $value A DateTime object
*
- * @return string A value as produced by PHP's date() function
+ * @return string A value as produced by PHP's date() function
*
* @throws UnexpectedTypeException if the given value is not a \DateTime instance
* @throws TransformationFailedException if the output timezone is not supported
@@ -27,7 +27,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
*
* @param DateTime $value A DateTime object
*
- * @return integer A timestamp
+ * @return integer A timestamp
*
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
* @throws TransformationFailedException if the output timezone is not supported
@@ -48,7 +48,7 @@ public function __construct($precision = null, $grouping = null, $roundingMode =
*
* @param number $value Normalized number
*
- * @return string Localized money string.
+ * @return string Localized money string.
*
* @throws UnexpectedTypeException if the given value is not numeric
* @throws TransformationFailedException if the value can not be transformed
@@ -66,7 +66,7 @@ public function __construct($precision = null, $type = null)
*
* @param number $value Normalized value
*
- * @return number Percentage value
+ * @return number Percentage value
*
* @throws UnexpectedTypeException if the given value is not numeric
* @throws TransformationFailedException if the value could not be transformed
@@ -101,7 +101,7 @@ public function transform($value)
*
* @param number $value Percentage value.
*
- * @return number Normalized value.
+ * @return number Normalized value.
*
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the value could not be transformed
@@ -26,7 +26,7 @@ class ValueToStringTransformer implements DataTransformerInterface
*
* @param mixed $value Mixed value.
*
- * @return string String value.
+ * @return string String value.
*
* @throws UnexpectedTypeException if the given value is not a string or number
*/
@@ -48,7 +48,7 @@ public function transform($value)
*
* @param string $value String value.
*
- * @return string String value.
+ * @return string String value.
*
* @throws UnexpectedTypeException if the given value is not a string
*/
@@ -89,7 +89,7 @@ public function guessPattern($class, $property)
*
* @param Constraint $constraint The constraint to guess for
*
- * @return TypeGuess The guessed field class and options
+ * @return TypeGuess The guessed field class and options
*/
public function guessTypeForConstraint(Constraint $constraint)
{
@@ -178,7 +178,7 @@ public function guessTypeForConstraint(Constraint $constraint)
*
* @param Constraint $constraint The constraint to guess for
*
- * @return Guess The guess whether the field is required
+ * @return Guess The guess whether the field is required
*/
public function guessRequiredForConstraint(Constraint $constraint)
{
@@ -194,7 +194,7 @@ public function guessRequiredForConstraint(Constraint $constraint)
*
* @param Constraint $constraint The constraint to guess for
*
- * @return Guess The guess for the maximum length
+ * @return Guess The guess for the maximum length
*/
public function guessMaxLengthForConstraint(Constraint $constraint)
{
@@ -282,7 +282,7 @@ public function guessPatternForConstraint(Constraint $constraint)
* @param mixed $default The default value assumed if no other value
* can be guessed.
*
- * @return Guess The guessed value with the highest confidence
+ * @return Guess The guessed value with the highest confidence
*/
protected function guess($class, $property, \Closure $closure, $defaultValue = null)
{
@@ -89,11 +89,11 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
}
}
- $template = $violation->getMessageTemplate();
- $parameters = $violation->getMessageParameters();
- $pluralization = $violation->getMessagePluralization();
-
- $this->scope->addError(new FormError($template, $parameters, $pluralization));
+ $this->scope->addError(new FormError(
+ $violation->getMessageTemplate(),
+ $violation->getMessageParameters(),
+ $violation->getMessagePluralization()
+ ));
}
/**
@@ -177,9 +177,9 @@ private function matchChild(PropertyPathIteratorInterface $it)
* Reconstructs a property path from a violation path and a form tree.
*
* @param ViolationPath $violationPath The violation path.
- * @param FormInterface $origin The root form of the tree.
+ * @param FormInterface $origin The root form of the tree.
*
- * @return RelativePath The reconstructed path.
+ * @return RelativePath The reconstructed path.
*/
private function reconstructPath(ViolationPath $violationPath, FormInterface $origin)
{
@@ -220,10 +220,10 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or
// Property path of a mapped form is null
// Should not happen, bail out
break;
- } else {
- $propertyPathBuilder->replace($i, 1, $propertyPath);
- $i += $propertyPath->getLength();
}
+
+ $propertyPathBuilder->replace($i, 1, $propertyPath);
+ $i += $propertyPath->getLength();
}
}
@@ -43,7 +43,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
/**
* @var string
*/
- private $string = '';
+ private $pathAsString = '';
/**
* @var integer
@@ -59,32 +59,28 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function __construct($violationPath)
{
$path = new PropertyPath($violationPath);
- $pathElements = $path->getElements();
- $pathPositions = $path->getPositions();
- $elements = array();
- $positions = array();
- $isIndex = array();
- $mapsForm = array();
+ $elements = $path->getElements();
+ $positions = $path->getPositions();
$data = false;
- for ($i = 0, $l = count($pathElements); $i < $l; ++$i) {
+ for ($i = 0, $l = count($elements); $i < $l; ++$i) {
if (!$data) {
// The element "data" has not yet been passed
- if ('children' === $pathElements[$i] && $path->isProperty($i)) {
+ if ('children' === $elements[$i] && $path->isProperty($i)) {
// Skip element "children"
++$i;
// Next element must exist and must be an index
- // Otherwise not a valid path
+ // Otherwise consider this the end of the path
if ($i >= $l || !$path->isIndex($i)) {
- return;
+ break;
}
- $elements[] = $pathElements[$i];
- $positions[] = $pathPositions[$i];
- $isIndex[] = true;
- $mapsForm[] = true;
- } elseif ('data' === $pathElements[$i] && $path->isProperty($i)) {
+ $this->elements[] = $elements[$i];
+ $this->positions[] = $positions[$i];
+ $this->isIndex[] = true;
+ $this->mapsForm[] = true;
+ } elseif ('data' === $elements[$i] && $path->isProperty($i)) {
// Skip element "data"
++$i;
@@ -93,32 +89,28 @@ public function __construct($violationPath)
break;
}
- $elements[] = $pathElements[$i];
- $positions[] = $pathPositions[$i];
- $isIndex[] = $path->isIndex($i);
- $mapsForm[] = false;
+ $this->elements[] = $elements[$i];
+ $this->positions[] = $positions[$i];
+ $this->isIndex[] = $path->isIndex($i);
+ $this->mapsForm[] = false;
$data = true;
} else {
// Neither "children" nor "data" property found
- // Be nice and consider this the end of the path
+ // Consider this the end of the path
break;
}
} else {
// Already after the "data" element
// Pick everything as is
- $elements[] = $pathElements[$i];
- $positions[] = $pathPositions[$i];
- $isIndex[] = $path->isIndex($i);
- $mapsForm[] = false;
+ $this->elements[] = $elements[$i];
+ $this->positions[] = $positions[$i];
+ $this->isIndex[] = $path->isIndex($i);
+ $this->mapsForm[] = false;
}
}
- $this->elements = $elements;
- $this->positions = $positions;
- $this->isIndex = $isIndex;
- $this->mapsForm = $mapsForm;
- $this->length = count($elements);
- $this->string = $violationPath;
+ $this->length = count($this->elements);
+ $this->pathAsString = $violationPath;
$this->resizeString();
}
@@ -128,7 +120,7 @@ public function __construct($violationPath)
*/
public function __toString()
{
- return $this->string;
+ return $this->pathAsString;
}
/**
@@ -215,7 +207,7 @@ public function isIndex($index)
*
* @param integer $index The element index.
*
- * @return Boolean Whether the element maps to a form.
+ * @return Boolean Whether the element maps to a form.
*/
public function mapsForm($index)
{
@@ -241,7 +233,7 @@ private function resizeString()
$lastIndex = $this->length - 1;
if ($lastIndex < 0) {
- $this->string = '';
+ $this->pathAsString = '';
} else {
// +1 for the dot/opening bracket
$length = $this->positions[$lastIndex] + strlen($this->elements[$lastIndex]) + 1;
@@ -251,7 +243,7 @@ private function resizeString()
++$length;
}
- $this->string = substr($this->string, 0, $length);
+ $this->pathAsString = substr($this->pathAsString, 0, $length);
}
}
}
Oops, something went wrong.

0 comments on commit 3bc32da

Please sign in to comment.