Skip to content

Commit f95afa3

Browse files
committed
use readable type if the property is not writeable
reorder also erros to report non-writable property first
1 parent 6b705bd commit f95afa3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Rules/SetValueMethodRule.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,28 @@ public function processNode(Node $node, Scope $scope): array
9090
}
9191

9292
$property = $class->getProperty($fieldName, $scope);
93-
$propertyType = $property->getWritableType();
9493

95-
if (!$propertyType->accepts($valueType, true)->yes()) {
94+
if (!$property->isWritable() && $methodName !== 'setReadOnlyValue') {
9695
$errors[] = sprintf(
97-
'Entity %s: property $%s (%s) does not accept %s.',
96+
'Entity %s: property $%s is read-only.',
9897
$className,
99-
$fieldName,
100-
$propertyType->describe(VerbosityLevel::typeOnly()),
101-
$valueType->describe(VerbosityLevel::typeOnly())
98+
$fieldName
10299
);
103100
continue;
104101
}
105102

106-
if (!$property->isWritable() && $methodName !== 'setReadOnlyValue') {
103+
$propertyType = $property->getWritableType();
104+
if (!$property->isWritable()) {
105+
$propertyType = $property->getReadableType();
106+
}
107+
108+
if (!$propertyType->accepts($valueType, true)->yes()) {
107109
$errors[] = sprintf(
108-
'Entity %s: property $%s is read-only.',
110+
'Entity %s: property $%s (%s) does not accept %s.',
109111
$className,
110-
$fieldName
112+
$fieldName,
113+
$propertyType->describe(VerbosityLevel::typeOnly()),
114+
$valueType->describe(VerbosityLevel::typeOnly())
111115
);
112116
}
113117
}

0 commit comments

Comments
 (0)