|
27 | 27 | * It can also patch classes to turn docblocks into actual return types.
|
28 | 28 | * This behavior is controlled by the SYMFONY_PATCH_TYPE_DECLARATIONS env var,
|
29 | 29 | * which is a url-encoded array with the follow parameters:
|
30 |
| - * - force: any value enables deprecation notices - can be any of: |
| 30 | + * - "force": any value enables deprecation notices - can be any of: |
31 | 31 | * - "docblock" to patch only docblock annotations
|
32 | 32 | * - "object" to turn union types to the "object" type when possible (not recommended)
|
33 |
| - * - "1"/"0" to enable/disable patching of return types |
34 |
| - * - php: the target version of PHP - e.g. "7.1" doesn't generate "object" types |
| 33 | + * - "1" to add all possible return types including magic methods |
| 34 | + * - "0" to add possible return types excluding magic methods |
| 35 | + * - "php": the target version of PHP - e.g. "7.1" doesn't generate "object" types |
| 36 | + * - "deprecations": "1" to trigger a deprecation notice when a child class misses a |
| 37 | + * return type while the parent declares an "@return" annotation |
35 | 38 | *
|
36 | 39 | * Note that patching doesn't care about any coding style so you'd better to run
|
37 | 40 | * php-cs-fixer after, with rules "phpdoc_trim_consecutive_blank_line_separation"
|
@@ -177,6 +180,7 @@ public function __construct(callable $classLoader)
|
177 | 180 | $this->patchTypes += [
|
178 | 181 | 'force' => null,
|
179 | 182 | 'php' => null,
|
| 183 | + 'deprecations' => false, |
180 | 184 | ];
|
181 | 185 |
|
182 | 186 | if (!isset(self::$caseCheck)) {
|
@@ -571,7 +575,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
|
571 | 575 |
|
572 | 576 | $forcePatchTypes = $this->patchTypes['force'];
|
573 | 577 |
|
574 |
| - if ($canAddReturnType = $forcePatchTypes && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) { |
| 578 | + if ($canAddReturnType = null !== $forcePatchTypes && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) { |
575 | 579 | if ('void' !== (self::MAGIC_METHODS[$method->name] ?? 'void')) {
|
576 | 580 | $this->patchTypes['force'] = $forcePatchTypes ?: 'docblock';
|
577 | 581 | }
|
@@ -600,7 +604,7 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
|
600 | 604 | if (strncmp($ns, $declaringClass, $len)) {
|
601 | 605 | if ($canAddReturnType && 'docblock' === $this->patchTypes['force'] && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
|
602 | 606 | $this->patchMethod($method, $returnType, $declaringFile, $normalizedType);
|
603 |
| - } elseif ('' !== $declaringClass && null !== $this->patchTypes['force']) { |
| 607 | + } elseif ('' !== $declaringClass && $this->patchTypes['deprecations']) { |
604 | 608 | $deprecations[] = sprintf('Method "%s::%s()" will return "%s" as of its next major version. Doing the same in child class "%s" will be required when upgrading.', $declaringClass, $method->name, $normalizedType, $className);
|
605 | 609 | }
|
606 | 610 | }
|
|
0 commit comments