Skip to content

Commit b337d37

Browse files
authored
[deprecation] Add explicit warning to withPhpPolyfill() deprecated method + raise error on ->withPhpSets() miss-use on PHP 7.4- projects (#6790)
* [deprecation] Add explicit warning to withPhpPolyfill() deprecated method * [dx] Add explicit warning for withPhpSets() use in PHP 7.4- version to avoid magic true false args * cleanup unreachable code
1 parent d80e482 commit b337d37

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Configuration/RectorConfigBuilder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,12 @@ public function withAttributesSets(
499499
* @deprecated Already included in withPhpSets(), no need to repeat
500500
* make use of polyfill packages in composer.json
501501
*/
502-
public function withPhpPolyfill(): self
502+
public function withPhpPolyfill(): never
503503
{
504-
$this->sets[] = SetList::PHP_POLYFILLS;
505-
return $this;
504+
throw new InvalidConfigurationException(sprintf(
505+
'Method "%s()" is deprecated and is now part of ->withPhpSets() to avoid duplications and too granular configuration.',
506+
__METHOD__,
507+
));
506508
}
507509

508510
/**
@@ -537,7 +539,7 @@ public function withPhpSets(
537539

538540
$pickedArguments = array_filter(func_get_args());
539541
if ($pickedArguments !== []) {
540-
Notifier::notifyWithPhpSetsNotSuitableForPHP80();
542+
Notifier::errorWithPhpSetsNotSuitableForPHP74AndLower();
541543
}
542544

543545
if (count($pickedArguments) > 1) {

src/Console/Notifier.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\Console;
66

7+
use Rector\Exception\Configuration\InvalidConfigurationException;
78
use Symfony\Component\Console\Input\ArgvInput;
89
use Symfony\Component\Console\Output\ConsoleOutput;
910
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -27,17 +28,14 @@ public static function notifyNotSuitableMethodForPHP74(string $calledMethod): vo
2728
sleep(3);
2829
}
2930

30-
public static function notifyWithPhpSetsNotSuitableForPHP80(): void
31+
public static function errorWithPhpSetsNotSuitableForPHP74AndLower(): void
3132
{
3233
if (PHP_VERSION_ID >= 80000) {
3334
return;
3435
}
3536

36-
$message = 'The "withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use more explicit "withPhp53Sets()" ... "withPhp74Sets()" in lower PHP versions instead.';
37-
38-
$symfonyStyle = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
39-
$symfonyStyle->warning($message);
40-
41-
sleep(3);
37+
throw new InvalidConfigurationException(
38+
'The "->withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use more explicit "->withPhp53Sets()" ... "->withPhp74Sets()" in lower PHP versions instead.'
39+
);
4240
}
4341
}

0 commit comments

Comments
 (0)