Skip to content

Commit

Permalink
[DX] Suggest to use withSets() when using multiple PHP version, eg bo…
Browse files Browse the repository at this point in the history
…th php 7.4 and 8.0 on CI on Notifier messages (#5991)

* [DX] Suggest to use withSets() when using multiple PHP version, eg both php 7.4 and 8.0 on CI on Notifier messages

* fix

* inline

* [ci-review] Rector Rectify

* better show

* no need to change withSets

* clean up message

* clean up message

* clean up

* clean up

* remove not clear message about composer

* cs fix

* [ci-review] Rector Rectify

* clean

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user authored Jun 20, 2024
1 parent 891bfda commit cecb60d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/Composer/InstalledPackageResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class InstalledPackageResolver
*/
private array $resolvedInstalledPackages = [];


/**
* @return InstalledPackage[]
*/
Expand Down
20 changes: 10 additions & 10 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,71 +512,71 @@ public function withPhpSets(
// suitable for PHP 7.4 and lower, before named args
public function withPhp53Sets(): self
{
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__, 'withPhpSets');
Notifier::notifyNotSuitableMethodForPHP80(__METHOD__);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$this->sets[] = LevelSetList::UP_TO_PHP_74;
return $this;
Expand Down Expand Up @@ -610,7 +610,7 @@ public function withPreparedSets(
// composer based
bool $twig = false,
): self {
Notifier::notifyNotSuitableMethodForPHP74(__METHOD__, 'withSets');
Notifier::notifyNotSuitableMethodForPHP74(__METHOD__);

if ($deadCode) {
$this->sets[] = SetList::DEAD_CODE;
Expand Down
25 changes: 13 additions & 12 deletions src/Console/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@

final class Notifier
{
public static function notifyNotSuitableMethodForPHP74(string $calledMethod, string $recommendedMethod): void
public static function notifyNotSuitableMethodForPHP74(string $calledMethod): void
{
if (PHP_VERSION_ID >= 80000) {
return;
}

$message = sprintf(
'The "%s()" method uses named arguments. Its suitable for PHP 8.0+. In lower PHP versions, use "%s()" method instead',
$calledMethod,
$recommendedMethod
'The "%s()" method uses named arguments. Its suitable for PHP 8.0+. In lower PHP versions, use "withSets([...])" method instead',
$calledMethod
);

$symfonyStyle = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
Expand All @@ -28,17 +27,19 @@ public static function notifyNotSuitableMethodForPHP74(string $calledMethod, str
sleep(3);
}

public static function notifyNotSuitableMethodForPHP80(string $calledMethod, string $recommendedMethod): void
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 "%s()" method instead.',
$calledMethod,
$recommendedMethod
'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());
Expand All @@ -53,10 +54,10 @@ public static function notifyWithPhpSetsNotSuitableForPHP80(): void
return;
}

$message = sprintf(
'The "withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. In lower PHP versions, use withPhp53Sets() ... withPhp74Sets() method instead. One at a time.%sTo use your composer.json PHP version, keep arguments of this method.',
PHP_EOL
);
$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+.';

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

0 comments on commit cecb60d

Please sign in to comment.