[PropertyAccess] the property path constructor already implements the type check

This commit is contained in:
Tobias Schultze 2015-02-19 13:40:39 +01:00
parent 4e11c0710b
commit 9cacecbf79

View File

@ -40,10 +40,8 @@ class PropertyAccessor implements PropertyAccessorInterface
*/ */
public function getValue($objectOrArray, $propertyPath) public function getValue($objectOrArray, $propertyPath)
{ {
if (is_string($propertyPath)) { if (!$propertyPath instanceof PropertyPathInterface) {
$propertyPath = new PropertyPath($propertyPath); $propertyPath = new PropertyPath($propertyPath);
} elseif (!$propertyPath instanceof PropertyPathInterface) {
throw new UnexpectedTypeException($propertyPath, 'string or Symfony\Component\PropertyAccess\PropertyPathInterface');
} }
$propertyValues = & $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength()); $propertyValues = & $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength());
@ -56,10 +54,8 @@ class PropertyAccessor implements PropertyAccessorInterface
*/ */
public function setValue(&$objectOrArray, $propertyPath, $value) public function setValue(&$objectOrArray, $propertyPath, $value)
{ {
if (is_string($propertyPath)) { if (!$propertyPath instanceof PropertyPathInterface) {
$propertyPath = new PropertyPath($propertyPath); $propertyPath = new PropertyPath($propertyPath);
} elseif (!$propertyPath instanceof PropertyPathInterface) {
throw new UnexpectedTypeException($propertyPath, 'string or Symfony\Component\PropertyAccess\PropertyPathInterface');
} }
$propertyValues = & $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1); $propertyValues = & $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);