Skip to content

Commit

Permalink
Merge branch 'master' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed May 3, 2021
2 parents 114bb0e + 45987c9 commit 04a087d
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 @@ -24,6 +24,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 @@ -78,16 +79,39 @@ public function doRun(InputInterface $input, OutputInterface $output): int
? $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 @@ -26,6 +26,8 @@
*/
final class Utils
{
private static $deprecations = [];

/**
* Converts a camel cased string to a snake cased string.
*/
Expand Down Expand Up @@ -161,6 +163,12 @@ public static function triggerDeprecation(string $message, string $exceptionClas
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(): array
{
return self::$deprecations;
}
}

0 comments on commit 04a087d

Please sign in to comment.