From b748b78f2789b9ebdd07da19e2ca535f4840d8b5 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Fri, 6 Feb 2015 15:33:31 +0100 Subject: [PATCH] Don't use non-setters methods as setters --- Mapping/ClassMetadata.php | 13 ++++++++----- Tests/Behat/TestBundle/Entity/Dummy.php | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Mapping/ClassMetadata.php b/Mapping/ClassMetadata.php index cb5259eead0..3da886fa8a7 100644 --- a/Mapping/ClassMetadata.php +++ b/Mapping/ClassMetadata.php @@ -169,15 +169,13 @@ public function getAttributes( if (!isset($attributes[$attributeName])) { $attributes[$attributeName] = [ - 'readable' => false, - 'writable' => false, 'description' => (new DocBlock($reflMethod))->getShortDescription(), ]; } if (0 === $reflMethod->getNumberOfRequiredParameters()) { $attributes[$attributeName]['readable'] = true; - } else { + } elseif (0 === strpos($methodName, 'set')) { $attributes[$attributeName]['writable'] = true; } } @@ -196,6 +194,11 @@ public function getAttributes( // populate attributes foreach ($attributes as $attributeName => $attribute) { + if (!isset($attribute['readable']) && !isset($attribute['writable'])) { + unset($attributes[$attributeName]); + continue; + } + $this->populateAttribute($attributeName, $attributes[$attributeName], $validationGroups); } } @@ -288,8 +291,8 @@ private function populateAttribute($name, array &$attribute, array $validationGr $attribute['readable'] = false; } - if (!isset($attribute['writeable'])) { - $attribute['writeable'] = false; + if (!isset($attribute['writable'])) { + $attribute['writable'] = false; } foreach ($this->validatorClassMetadata->getPropertyMetadata($name) as $propertyMetadata) { diff --git a/Tests/Behat/TestBundle/Entity/Dummy.php b/Tests/Behat/TestBundle/Entity/Dummy.php index 0f65638544e..64c137a6753 100644 --- a/Tests/Behat/TestBundle/Entity/Dummy.php +++ b/Tests/Behat/TestBundle/Entity/Dummy.php @@ -55,4 +55,9 @@ public function getName() { return $this->name; } + + public function hasRole($role) + { + + } }