Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to find classes/interfaces/traits with missing return types: ADD THEM TO YOUR SHIT.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$namespace = 'PutYourProjectNamespaceHere\\';
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src')), '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH) as $file) {
require_once $file[0];
}
$symbols = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
$methods = [];
foreach ($symbols as $symbol) {
foreach ((new \ReflectionClass($symbol))->getMethods() as $method) {
if ($method->isConstructor()) {
continue;
}
if ($method->getReturnType()) {
continue;
}
if (0 !== strpos($method->getDeclaringClass()->getName(), $namespace)) {
continue;
}
if (false !== strpos($method->getDocComment(), '@return void')) {
continue;
}
$methods[] = $method->getDeclaringClass()->getName() . '#' . $method->getName();
}
}
var_dump(array_values(array_unique($methods)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.