Skip to content

Commit

Permalink
feature #5674 UX: Display deprecations to end-user (keradus)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.19-dev branch.

Discussion
----------

UX: Display deprecations to end-user

simplified approach of #3699

Commits
-------

de44afe UX: Display deprecations to end-user
  • Loading branch information
keradus committed May 3, 2021
2 parents c5d6614 + de44afe commit 45987c9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PhpCsFixer\Console\SelfUpdate\NewVersionChecker;
use PhpCsFixer\PharChecker;
use PhpCsFixer\ToolInfo;
use PhpCsFixer\Utils;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Command\ListCommand;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -83,16 +84,39 @@ public function doRun(InputInterface $input, OutputInterface $output)
? $output->getErrorOutput()
: ($input->hasParameterOption('--format', true) && 'txt' !== $input->getParameterOption('--format', null, true) ? null : $output)
;

if (null !== $stdErr) {
$warningsDetector = new WarningsDetector($this->toolInfo);
$warningsDetector->detectOldVendor();
$warningsDetector->detectOldMajor();
foreach ($warningsDetector->getWarnings() as $warning) {
$stdErr->writeln(sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', $warning));
$warnings = $warningsDetector->getWarnings();

if ($warnings) {
foreach ($warnings as $warning) {
$stdErr->writeln(sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', $warning));
}
$stdErr->writeln('');
}
}

$result = parent::doRun($input, $output);

if (
null !== $stdErr
&& $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE
) {
$triggeredDeprecations = array_unique(Utils::getTriggeredDeprecations());
sort($triggeredDeprecations);
if ($triggeredDeprecations) {
$stdErr->writeln('');
$stdErr->writeln($stdErr->isDecorated() ? '<bg=yellow;fg=black;>Detected deprecations in use:</>' : 'Detected deprecations in use:');
foreach ($triggeredDeprecations as $deprecation) {
$stdErr->writeln(sprintf('- %s', $deprecation));
}
}
}

return parent::doRun($input, $output);
return $result;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
final class Utils
{
private static $deprecations = [];

/**
* Calculate a bitmask for given constant names.
*
Expand Down Expand Up @@ -195,6 +197,12 @@ public static function triggerDeprecation($message, $exceptionClass = \RuntimeEx
throw new $exceptionClass("{$message} This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.");
}

self::$deprecations[] = $message;
@trigger_error($message, E_USER_DEPRECATED);
}

public static function getTriggeredDeprecations()
{
return self::$deprecations;
}
}

0 comments on commit 45987c9

Please sign in to comment.