8000 Add CI check ensuring interfaces have return types · symfony/symfony@48541fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 48541fd

Browse files
committed
Add CI check ensuring interfaces have return types
1 parent 9d8a9b6 commit 48541fd

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

.github/patch-types.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
if (false === getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) {
3+
$mode = $argv[1] ?? 'patch';
4+
if ('lint' !== $mode && false === getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) {
45
echo "Please define the SYMFONY_PATCH_TYPE_DECLARATIONS env var when running this script.\n";
56
exit(1);
67
}
@@ -11,6 +12,7 @@
1112

1213
Symfony\Component\ErrorHandler\DebugClassLoader::enable();
1314

15+
$missingReturnTypes = [];
1416
foreach ($loader->getClassMap() as $class => $file) {
1517
$file = realpath($file);
1618

@@ -53,13 +55,41 @@
5355
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/NotLoadableClass.php'):
5456
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionIntersectionTypeFixture.php'):
5557
case false !== strpos($file, '/src/Symfony/Component/VarDumper/Tests/Fixtures/ReflectionUnionTypeWithIntersectionFixture.php'):
58+
case false !== strpos($file, '/src/Symfony/Component/VarExporter/Internal'):
5659
case false !== strpos($file, '/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyGhost/ReadOnlyClass.php'):
5760
case false !== strpos($file, '/src/Symfony/Component/VarExporter/Tests/Fixtures/LazyProxy/ReadOnlyClass.php'):
5861
case false !== strpos($file, '/src/Symfony/Component/Cache/Traits/RelayProxy.php'):
5962
continue 2;
6063
}
6164

6265
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+
}
6385
}
6486

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+
}

.github/workflows/unit-tests.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ jobs:
148148
git checkout src/Symfony/Contracts/Service/ResetInterface.php
149149
git diff --exit-code
150150
151+
- name: Check interface return types
152+
if: "matrix.php == '8.1' && ! matrix.mode"
153+
run: |
154+
php .github/patch-types.php lint
155+
151156
- name: Run tests
152157
run: |
153158
_run_tests() {

0 commit comments

Comments
 (0)
0