8000 merged branch Tobion/pp-refactor (PR #4418) · haygus/symfony@0a47389 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a47389

Browse files
committed
merged branch Tobion/pp-refactor (PR symfony#4418)
Commits ------- e673a04 [OptionsResolver] clarify phpdoc 0cac404 [Form] refactored PropertyPth Discussion ---------- PropertyPath refactoring + CS fix --------------------------------------------------------------------------- by travisbot at 2012-05-25T21:49:01Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1437257) (merged e673a04 into ff4d446).
2 parents 96bfdac + e673a04 commit 0a47389

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed

src/Symfony/Component/Form/Util/PropertyPath.php

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ protected function &readProperty(&$objectOrArray, $property, $isIndex)
427427
*
428428
* @param object|array $objectOrArray The object or array to write to.
429429
* @param string $property The property to write.
430-
* @param string $singular The singular form of the property name or null.
430+
* @param string|null $singular The singular form of the property name or null.
431431
* @param Boolean $isIndex Whether to interpret the property as index.
432432
* @param mixed $value The value to write.
433433
*
@@ -526,7 +526,7 @@ protected function camelize($string)
526526
* Searches for add and remove methods.
527527
*
528528
* @param \ReflectionClass $reflClass The reflection class for the given object
529-
* @param string $singular The singular form of the property name or null.
529+
* @param string|null $singular The singular form of the property name or null.
530530
*
531531
* @return array|null An array containin the adder and remover when found, null otherwise.
532532
*
@@ -555,42 +555,32 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, $singular)
555555
}
556556

557557
return array($addMethod, $removeMethod);
558-
} else {
559-
// The plural form is the last element of the property path
560-
$plural = ucfirst($this->elements[$this->length - 1]);
561-
562-
// Any of the two methods is required, but not yet known
563-
$singulars = (array) FormUtil::singularify($plural);
564-
565-
foreach ($singulars as $singular) {
566-
$methodsFound = 0;
567-
$addMethodFound = false;
568-
$addMethodName = 'add' . $singular;
569-
$removeMethodName = 'remove' . $singular;
570-
571-
if ($this->isAccessible($reflClass, $addMethodName, 1)) {
572-
$addMethod = $addMethodName;
573-
$addMethodFound = true;
574-
$methodsFound++;
575-
}
558+
}
576559

577-
if ($this->isAccessible($reflClass, $removeMethodName, 1)) {
578-
$removeMethod = $removeMethodName;
579-
$methodsFound++;
580-
}
560+
// The plural form is the last element of the property path
561+
$plural = ucfirst($this->elements[$this->length - 1]);
581562

582-
if (2 == $methodsFound) {
583-
return array($addMethod, $removeMethod);
584-
}
563+
// Any of the two methods is required, but not yet known
564+
$singulars = (array) FormUtil::singularify($plural);
585565

586-
if (1 == $methodsFound) {
587-
throw new InvalidPropertyException(sprintf(
588-
'Found the public method "%s", but did not find a public "%s" on class %s',
589-
$addMethodFound ? $addMethodName : $removeMethodName,
590-
$addMethodFound ? $removeMethodName : $addMethodName,
591-
$reflClass->getName()
592-
));
593-
}
566+
foreach ($singulars as $singular) {
567+
$addMethod = 'add' . $singular;
568+
$removeMethod = 'remove' . $singular;
569+
570+
$addMethodFound = $this->isAccessible($reflClass, $addMethod, 1);
571+
$removeMethodFound = $this->isAccessible($reflClass, $removeMethod, 1);
572+
573+
if ($addMethodFound && $removeMethodFound) {
574+
return array($addMethod, $removeMethod);
575+
}
576+
577+
if ($addMethodFound xor $removeMethodFound) {
578+
throw new InvalidPropertyException(sprintf(
579+
'Found the public method "%s", but did not find a public "%s" on class %s',
580+
$addMethodFound ? $addMethod : $removeMethod,
581+
$addMethodFound ? $removeMethod : $addMethod,
582+
$reflClass->getName()
583+
));
594584
}
595585
}
596586

src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ function replaceDefaults(array $defaultValues);
5959
/**
6060
* Sets optional options.
6161
*
62-
* This method is identical to {@ĺink setDefaults()}, only that no default values
63-
* are configured for the options. If these options are not passed to
64-
* {@link resolve()}, they will be missing in the final options array. This can be
65-
* helpful if you want to determine whether an option has been set or not.
62+
* This method declares valid option names without setting default values for them.
63+
* If these options are not passed to {@link resolve()} and no default has been set
64+
* for them, they will be missing in the final options array. This can be helpful
65+
* if you want to determine whether an option has been set or not because otherwise
66+
* {@link resolve()} would trigger an exception for unknown options.
6667
*
6768
* @param array $optionNames A list of option names.
6869
*
@@ -95,8 +96,9 @@ function setRequired(array $optionNames);
9596
*
9697
* @return OptionsResolverInterface The resolver instance.
9798
*
98-
* @throws Exception\InvalidOptionsException If an option has not been defined for
99-
* which an allowed value is set.
99+
* @throws Exception\InvalidOptionsException If an option has not been defined
100+
* (see {@link isKnown()}) for which
101+
* an allowed value is set.
100102
*/
101103
function setAllowedValues(array $allowedValues);
102104

0 commit comments

Comments
 (0)
0