Last active
September 5, 2018 10:27
-
-
Save Ocramius/36c92f5347edc6c7fd77 to your computer and use it in GitHub Desktop.
Script to find classes/interfaces/traits with missing return types: ADD THEM TO YOUR SHIT.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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