Skip to content

Commit b66b72c

Browse files
authored
add --dev option to breakpoint command (#3)
1 parent f20e0ad commit b66b72c

File tree

5 files changed

+44
-32
lines changed

5 files changed

+44
-32
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ This ensures upgrades stay on your radar without overwhelming you. No more "oops
7979

8080
<br>
8181

82+
It's safer to start upgrading dev packages first. You can spot them like this:
83+
84+
```bash
85+
vendor/bin/jack breakpoint --dev
86+
```
87+
88+
<br>
89+
8290
### 2. Open up Next Versions
8391

8492
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.

ecs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
declare(strict_types=1);
44

5-
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
65
use Symplify\EasyCodingStandard\Config\ECSConfig;
76

87
return ECSConfig::configure()
98
->withPreparedSets(psr12: true, common: true, symplify: true)
10-
->withRules([LineLengthFixer::class])
119
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
1210
->withRootFiles();

src/Command/BreakPointCommand.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
final class BreakPointCommand extends Command
1818
{
1919
public function __construct(
20+
private readonly SymfonyStyle $symfonyStyle,
2021
private readonly OutdatedComposerFactory $outdatedComposerFactory,
2122
private readonly ComposerOutdatedResponseProvider $composerOutdatedResponseProvider
2223
) {
@@ -28,6 +29,7 @@ protected function configure(): void
2829
$this->setName('breakpoint');
2930

3031
$this->setDescription('Let your CI tell you, if there is too many major-version outdated packages');
32+
$this->addOption('dev', null, InputOption::VALUE_NONE, 'Focus on dev packages only');
3133

3234
$this->addOption(
3335
'limit',
@@ -41,15 +43,15 @@ protected function configure(): void
4143
protected function execute(InputInterface $input, OutputInterface $output): int
4244
{
4345
$maxOutdatePackages = (int) $input->getOption('limit');
46+
$onlyDev = (bool) $input->getOption('dev');
4447

45-
$symfonyStyle = new SymfonyStyle($input, $output);
46-
$symfonyStyle->writeln('<fg=green>Analyzing "composer.json" for major outdated packages</>');
48+
$this->symfonyStyle->writeln('<fg=green>Analyzing "composer.json" for major outdated packages</>');
4749

4850
$responseJsonContents = $this->composerOutdatedResponseProvider->provide();
4951

5052
$responseJson = Json::decode($responseJsonContents, true);
5153
if (! isset($responseJson[ComposerKey::INSTALLED_KEY])) {
52-
$symfonyStyle->success('All packages are up to date');
54+
$this->symfonyStyle->success('All packages are up to date');
5355

5456
return self::SUCCESS;
5557
}
@@ -60,32 +62,34 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6062
$composerJsonFilePath
6163
);
6264

63-
$symfonyStyle->title(
65+
$this->symfonyStyle->title(
6466
sprintf(
6567
'Found %d outdated package%s',
66-
$outdatedComposer->count(),
67-
$outdatedComposer->count() > 1 ? 's' : ''
68+
$outdatedComposer->count($onlyDev),
69+
$outdatedComposer->count($onlyDev) > 1 ? 's' : ''
6870
)
6971
);
7072

71-
foreach ($outdatedComposer->getPackages() as $outdatedPackage) {
72-
$symfonyStyle->writeln(sprintf('The "<fg=green>%s</>" package is outdated', $outdatedPackage->getName()));
73+
foreach ($outdatedComposer->getPackages($onlyDev) as $outdatedPackage) {
74+
$this->symfonyStyle->writeln(
75+
sprintf('The "<fg=green>%s</>" package is outdated', $outdatedPackage->getName())
76+
);
7377

74-
$symfonyStyle->writeln(sprintf(
78+
$this->symfonyStyle->writeln(sprintf(
7579
' * Your version %s is <fg=%s>%s</>',
7680
$outdatedPackage->getCurrentVersion(),
7781
$outdatedPackage->isVeryOld() ? 'red' : 'yellow',
7882
$outdatedPackage->getCurrentVersionAge(),
7983
));
8084

81-
$symfonyStyle->writeln(sprintf(' * Bump to %s', $outdatedPackage->getLatestVersion()));
82-
$symfonyStyle->newLine();
85+
$this->symfonyStyle->writeln(sprintf(' * Bump to %s', $outdatedPackage->getLatestVersion()));
86+
$this->symfonyStyle->newLine();
8387
}
8488

85-
$symfonyStyle->newLine();
89+
$this->symfonyStyle->newLine();
8690
if ($outdatedComposer->count() >= $maxOutdatePackages) {
8791
// to much → fail
88-
$symfonyStyle->error(sprintf(
92+
$this->symfonyStyle->error(sprintf(
8993
'There %s %d outdated package%s. Update couple of them to get under %d limit',
9094
$outdatedComposer->count() > 1 ? 'are' : 'is',
9195
$outdatedComposer->count(),
@@ -98,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
98102

99103
if ($outdatedComposer->count() > max(1, $maxOutdatePackages - 5)) {
100104
// to much → fail
101-
$symfonyStyle->warning(sprintf(
105+
$this->symfonyStyle->warning(sprintf(
102106
'There are %d outdated packages. Soon, the count will go over %d limit and this job will fail.%sUpgrade in time',
103107
$outdatedComposer->count(),
104108
$maxOutdatePackages,
@@ -109,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
109113
}
110114

111115
// to many → fail
112-
$symfonyStyle->success(
116+
$this->symfonyStyle->success(
113117
sprintf('Still far away from limit %d. Good job keeping your project up to date!', $maxOutdatePackages)
114118
);
115119

src/Command/OpenVersionsCommand.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ final class OpenVersionsCommand extends Command
2222
public function __construct(
2323
private readonly NextVersionResolver $nextVersionResolver,
2424
private readonly OutdatedComposerFactory $outdatedComposerFactory,
25-
private readonly ComposerOutdatedResponseProvider $composerOutdatedResponseProvider
25+
private readonly ComposerOutdatedResponseProvider $composerOutdatedResponseProvider,
26+
private readonly SymfonyStyle $symfonyStyle
2627
) {
2728
parent::__construct();
2829
}
@@ -42,15 +43,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4243
{
4344
$composerJsonFilePath = getcwd() . '/composer.json';
4445

45-
$symfonyStyle = new SymfonyStyle($input, $output);
46-
$symfonyStyle->title('Analyzing "composer.json" for outdated packages');
47-
$symfonyStyle->writeln(' This might take 10-30 seconds to finish, depending on your dependency count');
46+
$this->symfonyStyle->title('Analyzing "composer.json" for outdated packages');
47+
$this->symfonyStyle->writeln(' This might take 10-30 seconds to finish, depending on your dependency count');
4848

4949
$responseJsonContents = $this->composerOutdatedResponseProvider->provide();
5050

5151
$responseJson = Json::decode($responseJsonContents, true);
5252
if (! isset($responseJson[ComposerKey::INSTALLED_KEY])) {
53-
$symfonyStyle->success('All packages are up to date. You are the best!');
53+
$this->symfonyStyle->success('All packages are up to date. You are the best!');
5454

5555
return self::SUCCESS;
5656
}
@@ -60,15 +60,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6060
$composerJsonFilePath
6161
);
6262

63-
$symfonyStyle->warning(
63+
$this->symfonyStyle->warning(
6464
sprintf(
6565
'Found %d outdated package%s',
6666
$outdatedComposer->count(),
6767
$outdatedComposer->count() === 1 ? '' : 's'
6868
)
6969
);
7070

71-
$symfonyStyle->listing([
71+
$this->symfonyStyle->listing([
7272
sprintf(
7373
'%d prod package%s',
7474
$outdatedComposer->getProdPackagesCount(),
@@ -81,8 +81,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181
),
8282
]);
8383

84-
$symfonyStyle->newLine();
85-
$symfonyStyle->title('Opening version constraints in "composer.json"');
84+
$this->symfonyStyle->newLine();
85+
$this->symfonyStyle->title('Opening version constraints in "composer.json"');
8686

8787
$limit = (int) $input->getOption('limit');
8888
$isDryRun = (bool) $input->getOption('dry-run');
@@ -112,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
112112
$openedVersion
113113
);
114114

115-
$symfonyStyle->writeln(sprintf(
115+
$this->symfonyStyle->writeln(sprintf(
116116
' * Opened "<fg=green>%s</>" package to "<fg=yellow>%s</>" version',
117117
$outdatedPackage->getName(),
118118
$openedVersion
@@ -130,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
130130
FileSystem::write($composerJsonFilePath, $composerJsonContents . PHP_EOL);
131131
}
132132

133-
$symfonyStyle->success(
133+
$this->symfonyStyle->success(
134134
sprintf(
135135
'%d packages %s opened up to the next nearest version.%s%s "composer update" to push versions up',
136136
$openedPackageCount,

src/ValueObject/OutdatedComposer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ public function getDevPackages(): array
4646
);
4747
}
4848

49-
public function count(): int
49+
public function count(bool $onlyDev = false): int
5050
{
51-
return count($this->outdatedPackages);
51+
$packages = $onlyDev ? $this->getDevPackages() : $this->outdatedPackages;
52+
53+
return count($packages);
5254
}
5355

5456
/**
5557
* @return OutdatedPackage[]
5658
*/
57-
public function getPackages(): array
59+
public function getPackages(bool $onlyDev = false): array
5860
{
59-
return $this->outdatedPackages;
61+
return $onlyDev ? $this->getDevPackages() : $this->outdatedPackages;
6062
}
6163

6264
/**

0 commit comments

Comments
 (0)