Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8311f21

Browse filesBrowse files
committed
[ErrorHandler] Add helper script to patch type declarations
1 parent 2085ff8 commit 8311f21
Copy full SHA for 8311f21

File tree

2 files changed

+89
-0
lines changed
Filter options

2 files changed

+89
-0
lines changed
+86Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* This file is part of the Symfony package.
6+
*
7+
* (c) Fabien Potencier <fabien@symfony.com>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
if (\in_array('-h', $argv) || \in_array('--help', $argv)) {
14+
echo implode(PHP_EOL, [
15+
' Patches type declarations to fix incompatibility with Symfony 6.',
16+
'',
17+
' Available options:',
18+
' SYMFONY_PATCH_TYPE_DECLARATIONS',
19+
' An url-encoded string to change the behavior of the script. Available parameters:',
20+
' - "force": any value enables deprecation notices - can be any of:',
21+
' - "phpdoc" to patch only docblock annotations',
22+
' - "2" to add all possible return types',
23+
' - "1" to add return types but only to tests/final/internal/private methods',
24+
' - "php": the target version of PHP - e.g. "7.1" doesn\'t generate "object" types',
25+
' - "deprecations": "1" to trigger a deprecation notice when a child class misses a',
26+
' return type while the parent declares an "@return" annotation',
27+
'',
28+
' SYMFONY_PATCH_TYPE_EXCLUDE',
29+
' A regex matched against the full path to the class - any match will be excluded',
30+
'',
31+
' Example: "SYMFONY_PATCH_TYPE_DECLARATIONS=php=7.4 ./patch-type-declarations"',
32+
]);
33+
exit;
34+
}
35+
36+
if (false === getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) {
37+
putenv('SYMFONY_PATCH_TYPE_DECLARATIONS=force=2');
38+
echo 'No SYMFONY_PATCH_TYPE_DECLARATIONS env var set, patching type declarations in all methods (run the command with "-h" for more information).'.PHP_EOL;
39+
}
40+
41+
if (is_file($autoload = __DIR__.'/../../../autoload.php')) {
42+
// noop
43+
} elseif (is_file($autoload = __DIR__.'/../../../../../autoload.php')) {
44+
// noop
45+
} else {
46+
echo PHP_EOL.' /!\ Cannot find the Composer autoloader, did you forget to run "composer install"?'.PHP_EOL;
47+
exit(1);
48+
}
49+
50+
if (is_file($phpunitAutoload = dirname($autoload).'/bin/.phpunit/phpunit/vendor/autoload.php')) {
51+
require $phpunitAutoload;
52+
}
53+
54+
$loader = require $autoload;
55+
56+
Symfony\Component\ErrorHandler\DebugClassLoader::enable();
57+
58+
$deprecations = [];
59+
set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations) {
60+
if (\E_USER_DEPRECATED !== $type) {
61+
return;
62+
}
63+
64+
[,,,,, $class,] = explode('"', $msg);
65+
$deprecations[$class][] = $msg;
66+
});
67+
68+
$exclude = getenv('SYMFONY_PATCH_TYPE_EXCLUDE') ?: null;
69+
foreach ($loader->getClassMap() as $class => $file) {
70+
if ($exclude && preg_match($exclude, realpath($file))) {
71+
continue;
72+
}
73+
74+
class_exists($class);
75+
}
76+
77+
Symfony\Component\ErrorHandler\DebugClassLoader::checkClasses();
78+
79+
foreach ($deprecations as $class => $classDeprecations) {
80+
echo $class.PHP_EOL;
81+
echo implode(PHP_EOL, $classDeprecations).PHP_EOL.PHP_EOL;
82+
}
83+
84+
if ($deprecations && false !== strpos(getenv('SYMFONY_PATCH_TYPE_DECLARATIONS') ?? '', 'force')) {
85+
echo 'These deprecations might be fixed by the patch script, run this again to check for type deprecations.'.PHP_EOL;
86+
}

‎src/Symfony/Component/ErrorHandler/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorHandler/composer.json
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
"/Tests/"
3232
]
3333
},
34+
"bin": [
35+
"Resources/bin/patch-type-declarations"
36+
],
3437
"minimum-stability": "dev"
3538
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.