|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -if (false === getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) { |
| 3 | +$mode = $argv[1] ?? 'patch'; |
| 4 | +if ('lint' !== $mode && false === getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) { |
4 | 5 | echo "Please define the SYMFONY_PATCH_TYPE_DECLARATIONS env var when running this script.\n";
|
5 | 6 | exit(1);
|
6 | 7 | }
|
|
11 | 12 |
|
12 | 13 | Symfony\Component\ErrorHandler\DebugClassLoader::enable();
|
13 | 14 |
|
| 15 | +$missingReturnTypes = []; |
14 | 16 | foreach ($loader->getClassMap() as $class => $file) {
|
15 | 17 | $file = realpath($file);
|
16 | 18 |
|
|
53 | 55 | case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
|
54 | 56 | case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionIntersectionTypeFixture.php'):
|
55 | 57 | case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionUnionTypeWithIntersectionFixture.php'):
|
| 58 | + case false !== strpos($file, '/src/Symfony/Component/VarExporter/Internal'): |
56 | 59 | case false !== strpos($file, '/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyGhost/ReadOnlyClass.php'):
|
57 | 60 | case false !== strpos($file, '/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/ReadOnlyClass.php'):
|
58 | 61 | case false !== strpos($file, '/src/Symfony/Component/Cache/Traits/RelayProxy.php'):
|
59 | 62 | continue 2;
|
60 | 63 | }
|
61 | 64 |
|
62 | 65 | class_exists($class);
|
| 66 | + |
| 67 | + if ('lint' !== $mode) { |
| 68 | + continue; |
| 69 | + } |
| 70 | + |
| 71 | + $refl = new \ReflectionClass($class); |
| 72 | + foreach ($refl->getMethods() as $method) { |
| 73 | + if ( |
| 74 | + !$refl->isInterface() |
| 75 | + || $method->getReturnType() |
| 76 | + || str_contains($method->getDocComment(), '@return') |
| 77 | + || str_starts_with($method->getName(), '__') |
| 78 | + || $method->getDeclaringClass()->getName() !== $class |
| 79 | + ) { |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | + $missingReturnTypes[] = $class.'::'.$method->getName(); |
| 84 | + } |
63 | 85 | }
|
64 | 86 |
|
65 |
| -Symfony\Component\ErrorHandler\DebugClassLoader::checkClasses(); |
| 87 | +if ($missingReturnTypes) { |
| 88 | + echo \count($missingReturnTypes)." missing return types on interfaces\n\n"; |
| 89 | + echo implode("\n", $missingReturnTypes); |
| 90 | + exit(1); |
| 91 | +} |
| 92 | + |
| 93 | +if ('patch' === $mode) { |
| 94 | + Symfony\Component\ErrorHandler\DebugClassLoader::checkClasses(); |
| 95 | +} |
0 commit comments