Skip to content

Commit b748b78

Browse files
committed
Don't use non-setters methods as setters
1 parent d8ec4c6 commit b748b78

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Mapping/ClassMetadata.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,13 @@ public function getAttributes(
169169

170170
if (!isset($attributes[$attributeName])) {
171171
$attributes[$attributeName] = [
172-
'readable' => false,
173-
'writable' => false,
174172
'description' => (new DocBlock($reflMethod))->getShortDescription(),
175173
];
176174
}
177175

178176
if (0 === $reflMethod->getNumberOfRequiredParameters()) {
179177
$attributes[$attributeName]['readable'] = true;
180-
} else {
178+
} elseif (0 === strpos($methodName, 'set')) {
181179
$attributes[$attributeName]['writable'] = true;
182180
}
183181
}
@@ -196,6 +194,11 @@ public function getAttributes(
196194

197195
// populate attributes
198196
foreach ($attributes as $attributeName => $attribute) {
197+
if (!isset($attribute['readable']) && !isset($attribute['writable'])) {
198+
unset($attributes[$attributeName]);
199+
continue;
200+
}
201+
199202
$this->populateAttribute($attributeName, $attributes[$attributeName], $validationGroups);
200203
}
201204
}
@@ -288,8 +291,8 @@ private function populateAttribute($name, array &$attribute, array $validationGr
288291
$attribute['readable'] = false;
289292
}
290293

291-
if (!isset($attribute['writeable'])) {
292-
$attribute['writeable'] = false;
294+
if (!isset($attribute['writable'])) {
295+
$attribute['writable'] = false;
293296
}
294297

295298
foreach ($this->validatorClassMetadata->getPropertyMetadata($name) as $propertyMetadata) {

Tests/Behat/TestBundle/Entity/Dummy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public function getName()
5555
{
5656
return $this->name;
5757
}
58+
59+
public function hasRole($role)
60+
{
61+
62+
}
5863
}

0 commit comments

Comments
 (0)