1717final 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
0 commit comments