|
16 | 16 | use function array_map;
|
17 | 17 | use function count;
|
18 | 18 | use function is_string;
|
| 19 | +use function lcfirst; |
19 | 20 | use function sprintf;
|
20 | 21 | use function str_contains;
|
21 | 22 |
|
@@ -111,6 +112,8 @@ public function processNode(Node $node, Scope $scope): array
|
111 | 112 | 'read' => $read,
|
112 | 113 | 'written' => $written,
|
113 | 114 | 'node' => $property,
|
| 115 | + 'onlyReadable' => $property->isReadable() && !$property->isWritable(), |
| 116 | + 'onlyWritable' => $property->isWritable() && !$property->isReadable(), |
114 | 117 | ];
|
115 | 118 | }
|
116 | 119 |
|
@@ -222,18 +225,32 @@ public function processNode(Node $node, Scope $scope): array
|
222 | 225 | ->identifier('property.unused')
|
223 | 226 | ->build();
|
224 | 227 | } else {
|
225 |
| - $errors[] = RuleErrorBuilder::message(sprintf('%s is never read, only written.', $propertyName)) |
| 228 | + if ($data['onlyReadable']) { |
| 229 | + $errors[] = RuleErrorBuilder::message(sprintf('Readable %s is never read.', lcfirst($propertyName))) |
| 230 | + ->line($propertyNode->getStartLine()) |
| 231 | + ->identifier('property.neverRead') |
| 232 | + ->build(); |
| 233 | + } else { |
| 234 | + $errors[] = RuleErrorBuilder::message(sprintf('%s is never read, only written.', $propertyName)) |
| 235 | + ->line($propertyNode->getStartLine()) |
| 236 | + ->identifier('property.onlyWritten') |
| 237 | + ->tip($tip) |
| 238 | + ->build(); |
| 239 | + } |
| 240 | + } |
| 241 | + } elseif (!$data['written'] && (!array_key_exists($name, $uninitializedProperties) || !$this->checkUninitializedProperties)) { |
| 242 | + if ($data['onlyWritable']) { |
| 243 | + $errors[] = RuleErrorBuilder::message(sprintf('Writable %s is never written.', lcfirst($propertyName))) |
226 | 244 | ->line($propertyNode->getStartLine())
|
227 |
| - ->identifier('property.onlyWritten') |
| 245 | + ->identifier('property.neverWritten') |
| 246 | + ->build(); |
| 247 | + } else { |
| 248 | + $errors[] = RuleErrorBuilder::message(sprintf('%s is never written, only read.', $propertyName)) |
| 249 | + ->line($propertyNode->getStartLine()) |
| 250 | + ->identifier('property.onlyRead') |
228 | 251 | ->tip($tip)
|
229 | 252 | ->build();
|
230 | 253 | }
|
231 |
| - } elseif (!$data['written'] && (!array_key_exists($name, $uninitializedProperties) || !$this->checkUninitializedProperties)) { |
232 |
| - $errors[] = RuleErrorBuilder::message(sprintf('%s is never written, only read.', $propertyName)) |
233 |
| - ->line($propertyNode->getStartLine()) |
234 |
| - ->identifier('property.onlyRead') |
235 |
| - ->tip($tip) |
236 |
| - ->build(); |
237 | 254 | }
|
238 | 255 | }
|
239 | 256 |
|
|
0 commit comments