Skip to content

Commit

Permalink
Run with*Sets() notifications only on PHP 8.0 to avoid true/false/fal…
Browse files Browse the repository at this point in the history
…se/true configs (#5993)

* Remove notification on PHP 8.0 and higher, in case Rector is run on PHP 7.4 and 8.0

* remove withSets() from message as using constant lists is discouraged
  • Loading branch information
TomasVotruba authored Jun 21, 2024
1 parent 6b11f63 commit 07dc580
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 44 deletions.
23 changes: 4 additions & 19 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,75 +510,60 @@ public function withPhpSets(
return $this;
}

// suitable for PHP 7.4 and lower, before named args
/**
* Following methods are suitable for PHP 7.4 and lower, before named args
* Let's keep them without warning, in case Rector is run on both PHP 7.4 and PHP 8.0 in CI
*/
public function withPhp53Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_53;
return $this;
}

public function withPhp54Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_54;
return $this;
}

public function withPhp55Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_55;
return $this;
}

public function withPhp56Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_56;
return $this;
}

public function withPhp70Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_70;
return $this;
}

public function withPhp71Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_71;
return $this;
}

public function withPhp72Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_72;
return $this;
}

public function withPhp73Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_73;
return $this;
}

public function withPhp74Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

$this->sets[] = LevelSetList::UP_TO_PHP_74;
return $this;
}
Expand Down
26 changes: 1 addition & 25 deletions src/Console/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,13 @@ public static function notifyNotSuitableMethodForPHP74(string $calledMethod): vo
sleep(3);
}

public static function notifyNotSuitableMethodForPHP80(string $calledMethod): void
{
// current project version check
if (PHP_VERSION_ID < 80000) {
return;
}

$message = sprintf(
'The "%s()" method is suitable for PHP 7.4 and lower. Use the following methods instead:
- "withPhpSets()" in PHP 8.0+
- "withSets([...])" for use in both php ^7.2 and php 8.0+.',
$calledMethod
);

$symfonyStyle = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
$symfonyStyle->warning($message);

sleep(3);
}

public static function notifyWithPhpSetsNotSuitableForPHP80(): void
{
if (PHP_VERSION_ID >= 80000) {
return;
}

$message = 'The "withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use the following methods instead:
- "withPhp53Sets()" ... "withPhp74Sets()" in lower PHP versions
- "withSets([...])" for use both PHP ^7.2 and php 8.0+.';
$message = 'The "withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use more explicit "withPhp53Sets()" ... "withPhp74Sets()" in lower PHP versions instead.';

$symfonyStyle = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
$symfonyStyle->warning($message);
Expand Down

0 comments on commit 07dc580

Please sign in to comment.