diff --git a/README.md b/README.md index 45fdc98..40f80f3 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,14 @@ This ensures upgrades stay on your radar without overwhelming you. No more "oops
+It's safer to start upgrading dev packages first. You can spot them like this: + +```bash +vendor/bin/jack breakpoint --dev +``` + +
+ ### 2. Open up Next Versions We know we're behind the latest versions of our dependencies, but where to start? Which versions should be force to update first? We can get lot of conflicts if we try to bump wrong end of knot. diff --git a/ecs.php b/ecs.php index bc1550f..b100e7a 100644 --- a/ecs.php +++ b/ecs.php @@ -2,11 +2,9 @@ declare(strict_types=1); -use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() ->withPreparedSets(psr12: true, common: true, symplify: true) - ->withRules([LineLengthFixer::class]) ->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) ->withRootFiles(); diff --git a/src/Command/BreakPointCommand.php b/src/Command/BreakPointCommand.php index 9b442ca..5e77faf 100644 --- a/src/Command/BreakPointCommand.php +++ b/src/Command/BreakPointCommand.php @@ -17,6 +17,7 @@ final class BreakPointCommand extends Command { public function __construct( + private readonly SymfonyStyle $symfonyStyle, private readonly OutdatedComposerFactory $outdatedComposerFactory, private readonly ComposerOutdatedResponseProvider $composerOutdatedResponseProvider ) { @@ -28,6 +29,7 @@ protected function configure(): void $this->setName('breakpoint'); $this->setDescription('Let your CI tell you, if there is too many major-version outdated packages'); + $this->addOption('dev', null, InputOption::VALUE_NONE, 'Focus on dev packages only'); $this->addOption( 'limit', @@ -41,15 +43,15 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $maxOutdatePackages = (int) $input->getOption('limit'); + $onlyDev = (bool) $input->getOption('dev'); - $symfonyStyle = new SymfonyStyle($input, $output); - $symfonyStyle->writeln('Analyzing "composer.json" for major outdated packages'); + $this->symfonyStyle->writeln('Analyzing "composer.json" for major outdated packages'); $responseJsonContents = $this->composerOutdatedResponseProvider->provide(); $responseJson = Json::decode($responseJsonContents, true); if (! isset($responseJson[ComposerKey::INSTALLED_KEY])) { - $symfonyStyle->success('All packages are up to date'); + $this->symfonyStyle->success('All packages are up to date'); return self::SUCCESS; } @@ -60,32 +62,34 @@ protected function execute(InputInterface $input, OutputInterface $output): int $composerJsonFilePath ); - $symfonyStyle->title( + $this->symfonyStyle->title( sprintf( 'Found %d outdated package%s', - $outdatedComposer->count(), - $outdatedComposer->count() > 1 ? 's' : '' + $outdatedComposer->count($onlyDev), + $outdatedComposer->count($onlyDev) > 1 ? 's' : '' ) ); - foreach ($outdatedComposer->getPackages() as $outdatedPackage) { - $symfonyStyle->writeln(sprintf('The "%s" package is outdated', $outdatedPackage->getName())); + foreach ($outdatedComposer->getPackages($onlyDev) as $outdatedPackage) { + $this->symfonyStyle->writeln( + sprintf('The "%s" package is outdated', $outdatedPackage->getName()) + ); - $symfonyStyle->writeln(sprintf( + $this->symfonyStyle->writeln(sprintf( ' * Your version %s is %s', $outdatedPackage->getCurrentVersion(), $outdatedPackage->isVeryOld() ? 'red' : 'yellow', $outdatedPackage->getCurrentVersionAge(), )); - $symfonyStyle->writeln(sprintf(' * Bump to %s', $outdatedPackage->getLatestVersion())); - $symfonyStyle->newLine(); + $this->symfonyStyle->writeln(sprintf(' * Bump to %s', $outdatedPackage->getLatestVersion())); + $this->symfonyStyle->newLine(); } - $symfonyStyle->newLine(); + $this->symfonyStyle->newLine(); if ($outdatedComposer->count() >= $maxOutdatePackages) { // to much → fail - $symfonyStyle->error(sprintf( + $this->symfonyStyle->error(sprintf( 'There %s %d outdated package%s. Update couple of them to get under %d limit', $outdatedComposer->count() > 1 ? 'are' : 'is', $outdatedComposer->count(), @@ -98,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($outdatedComposer->count() > max(1, $maxOutdatePackages - 5)) { // to much → fail - $symfonyStyle->warning(sprintf( + $this->symfonyStyle->warning(sprintf( 'There are %d outdated packages. Soon, the count will go over %d limit and this job will fail.%sUpgrade in time', $outdatedComposer->count(), $maxOutdatePackages, @@ -109,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } // to many → fail - $symfonyStyle->success( + $this->symfonyStyle->success( sprintf('Still far away from limit %d. Good job keeping your project up to date!', $maxOutdatePackages) ); diff --git a/src/Command/OpenVersionsCommand.php b/src/Command/OpenVersionsCommand.php index fd423dc..d80020b 100644 --- a/src/Command/OpenVersionsCommand.php +++ b/src/Command/OpenVersionsCommand.php @@ -22,7 +22,8 @@ final class OpenVersionsCommand extends Command public function __construct( private readonly NextVersionResolver $nextVersionResolver, private readonly OutdatedComposerFactory $outdatedComposerFactory, - private readonly ComposerOutdatedResponseProvider $composerOutdatedResponseProvider + private readonly ComposerOutdatedResponseProvider $composerOutdatedResponseProvider, + private readonly SymfonyStyle $symfonyStyle ) { parent::__construct(); } @@ -42,15 +43,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $composerJsonFilePath = getcwd() . '/composer.json'; - $symfonyStyle = new SymfonyStyle($input, $output); - $symfonyStyle->title('Analyzing "composer.json" for outdated packages'); - $symfonyStyle->writeln(' This might take 10-30 seconds to finish, depending on your dependency count'); + $this->symfonyStyle->title('Analyzing "composer.json" for outdated packages'); + $this->symfonyStyle->writeln(' This might take 10-30 seconds to finish, depending on your dependency count'); $responseJsonContents = $this->composerOutdatedResponseProvider->provide(); $responseJson = Json::decode($responseJsonContents, true); if (! isset($responseJson[ComposerKey::INSTALLED_KEY])) { - $symfonyStyle->success('All packages are up to date. You are the best!'); + $this->symfonyStyle->success('All packages are up to date. You are the best!'); return self::SUCCESS; } @@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $composerJsonFilePath ); - $symfonyStyle->warning( + $this->symfonyStyle->warning( sprintf( 'Found %d outdated package%s', $outdatedComposer->count(), @@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ) ); - $symfonyStyle->listing([ + $this->symfonyStyle->listing([ sprintf( '%d prod package%s', $outdatedComposer->getProdPackagesCount(), @@ -81,8 +81,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int ), ]); - $symfonyStyle->newLine(); - $symfonyStyle->title('Opening version constraints in "composer.json"'); + $this->symfonyStyle->newLine(); + $this->symfonyStyle->title('Opening version constraints in "composer.json"'); $limit = (int) $input->getOption('limit'); $isDryRun = (bool) $input->getOption('dry-run'); @@ -112,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $openedVersion ); - $symfonyStyle->writeln(sprintf( + $this->symfonyStyle->writeln(sprintf( ' * Opened "%s" package to "%s" version', $outdatedPackage->getName(), $openedVersion @@ -130,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int FileSystem::write($composerJsonFilePath, $composerJsonContents . PHP_EOL); } - $symfonyStyle->success( + $this->symfonyStyle->success( sprintf( '%d packages %s opened up to the next nearest version.%s%s "composer update" to push versions up', $openedPackageCount, diff --git a/src/ValueObject/OutdatedComposer.php b/src/ValueObject/OutdatedComposer.php index eddd859..d560975 100644 --- a/src/ValueObject/OutdatedComposer.php +++ b/src/ValueObject/OutdatedComposer.php @@ -46,17 +46,19 @@ public function getDevPackages(): array ); } - public function count(): int + public function count(bool $onlyDev = false): int { - return count($this->outdatedPackages); + $packages = $onlyDev ? $this->getDevPackages() : $this->outdatedPackages; + + return count($packages); } /** * @return OutdatedPackage[] */ - public function getPackages(): array + public function getPackages(bool $onlyDev = false): array { - return $this->outdatedPackages; + return $onlyDev ? $this->getDevPackages() : $this->outdatedPackages; } /**