Skip to content

Commit 0f5f9fa

Browse files
authored
Merge pull request #3 from KieranFYI/master
Better type support
2 parents 89b1ca8 + fd85cc3 commit 0f5f9fa

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/CheckerCommand.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
194194
}
195195

196196
if ($error['type'] == 'param-mismatch') {
197-
$this->output->write('<info>' . $error['class'] . '::' . $error['method'] . '</info> - @param <fg=blue>'.$error['param'] . '</> ('.$error['doc-type'].') does not match method signature ('.$error['param-type'].').');
197+
$this->output->write('<info>' . $error['class'] . '::' . $error['method'] . '</info> - @param <fg=blue>'.$error['param'] . '</> ('.$error['doc-type'].') does not match method signature ('.$error['param-type'].').');
198198
}
199199

200200
if ($error['type'] == 'return-missing') {
201201
$this->output->write('<info>' . $error['class'] . '::' . $error['method'] . '</info> - @return missing.');
202202
}
203203

204204
if ($error['type'] == 'return-mismatch') {
205-
$this->output->write('<info>' . $error['class'] . '::' . $error['method'] . '</info> - @return <fg=blue>'.$error['doc-type'] . '</> does not match method signature ('.$error['return-type'].').');
205+
$this->output->write('<info>' . $error['class'] . '::' . $error['method'] . '</info> - @return <fg=blue>'.$error['doc-type'] . '</> does not match method signature ('.$error['return-type'].').');
206206
}
207207

208208
$this->output->writeln('');
@@ -323,7 +323,10 @@ protected function processFile($file)
323323
];
324324
}
325325
} elseif (!empty($type) && $method['docblock']['params'][$param] !== $type) {
326-
if ($type === 'array' && substr($method['docblock']['params'][$param], -2) === '[]') {
326+
if (
327+
($type === 'array' && substr($method['docblock']['params'][$param], -2) === '[]')
328+
|| $method['docblock']['params'][$param] === 'mixed'
329+
) {
327330
// Do nothing because this is fine.
328331
} else {
329332
$warnings = true;
@@ -345,6 +348,10 @@ protected function processFile($file)
345348

346349
if (!empty($method['return'])) {
347350
if (empty($method['docblock']['return'])) {
351+
// https://bugs.php.net/bug.php?id=75263
352+
if ($method['name'] === '__construct') {
353+
continue;
354+
}
348355
$warnings = true;
349356
$this->warnings[] = [
350357
'type' => 'return-missing',
@@ -368,7 +375,11 @@ protected function processFile($file)
368375
];
369376
}
370377
} elseif ($method['docblock']['return'] !== $method['return']) {
371-
if ($method['return'] === 'array' && substr($method['docblock']['return'], -2) === '[]') {
378+
if (
379+
($method['return'] === 'array' && substr($method['docblock']['return'], -2) === '[]')
380+
|| $method['docblock']['return'] === 'mixed'
381+
|| (strpos($method['docblock']['return'], '|') !== false && PHP_MAJOR_VERSION < 8)
382+
) {
372383
// Do nothing because this is fine.
373384
} else {
374385
$warnings = true;

src/DocBlockParser.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ protected function parseComment($comment)
131131
}
132132
// Default the trailing values
133133
$parts = array_pad($parts, $count, null);
134-
// Store as a mapped array
135-
$this->tags[$tag][] = array_combine(
134+
$mapped = array_combine(
136135
self::$vectors[$tag],
137136
$parts
138137
);
138+
139+
if (isset($mapped['var']) && substr( $mapped['var'], 0, 3) === '...') {
140+
$mapped['var'] = substr($mapped['var'], 3);
141+
}
142+
// Store as a mapped array
143+
$this->tags[$tag][] = $mapped;
139144
}
140145
else {
141146
// The tagged block is only text

0 commit comments

Comments
 (0)