Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run with*Sets() notifications only on PHP 8.0 to avoid true/false/false/true configs #5993

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,75 +509,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