44
55namespace Rector \Jack \Command ;
66
7+ use Entropy \Console \Contract \CommandInterface ;
8+ use Entropy \Console \ValueObject \ArgumentsAndOptions ;
79use Nette \Utils \Json ;
10+ use Rector \Console \ExitCode ;
811use Rector \Jack \Composer \ComposerOutdatedResponseProvider ;
912use Rector \Jack \Enum \ComposerKey ;
1013use Rector \Jack \OutdatedComposerFactory ;
11- use Symfony \Component \Console \Command \Command ;
12- use Symfony \Component \Console \Input \InputInterface ;
1314use Symfony \Component \Console \Input \InputOption ;
14- use Symfony \Component \Console \Output \OutputInterface ;
1515use Symfony \Component \Console \Style \SymfonyStyle ;
1616
17- final class BreakPointCommand extends Command
17+ final readonly class BreakPointCommand implements CommandInterface
1818{
1919 public function __construct (
20- private readonly OutdatedComposerFactory $ outdatedComposerFactory ,
21- private readonly ComposerOutdatedResponseProvider $ composerOutdatedResponseProvider
20+ private SymfonyStyle $ symfonyStyle ,
21+ private OutdatedComposerFactory $ outdatedComposerFactory ,
22+ private ComposerOutdatedResponseProvider $ composerOutdatedResponseProvider
2223 ) {
23- parent ::__construct ();
2424 }
2525
26- protected function configure ( ): void
26+ public function run ( ArgumentsAndOptions $ argumentsAndOptions ): int
2727 {
28- $ this ->setName ('breakpoint ' );
29-
30- $ this ->setDescription ('Let your CI tell you, if there is too many major-version outdated packages ' );
31- $ this ->addOption ('dev ' , null , InputOption::VALUE_NONE , 'Focus on dev packages only ' );
32-
33- $ this ->addOption (
34- 'limit ' ,
35- null ,
36- InputOption::VALUE_REQUIRED ,
37- 'Maximum number of outdated major version packages ' ,
38- 5
39- );
40-
41- $ this ->addOption (
42- 'ignore ' ,
43- null ,
44- InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
45- 'Ignore packages by name, e.g. "symfony/" or "symfony/console" ' ,
46- );
47- }
48-
49- protected function execute (InputInterface $ input , OutputInterface $ output ): int
50- {
51- $ symfonyStyle = new SymfonyStyle ($ input , $ output );
28+ // $symfonyStyle = new SymfonyStyle($input, $output);
5229
5330 $ maxOutdatePackages = (int ) $ input ->getOption ('limit ' );
5431 $ onlyDev = (bool ) $ input ->getOption ('dev ' );
5532
56- $ symfonyStyle ->writeln ('<fg=green>Analyzing "composer.json" for major outdated packages</> ' );
33+ $ this -> symfonyStyle ->writeln ('<fg=green>Analyzing "composer.json" for major outdated packages</> ' );
5734
5835 $ responseJsonContents = $ this ->composerOutdatedResponseProvider ->provide ();
5936
6037 $ responseJson = Json::decode ($ responseJsonContents , true );
6138 if (! isset ($ responseJson [ComposerKey::INSTALLED_KEY ])) {
62- $ symfonyStyle ->success ('All packages are up to date ' );
39+ $ this -> symfonyStyle ->success ('All packages are up to date ' );
6340
6441 return self ::SUCCESS ;
6542 }
@@ -82,11 +59,11 @@ static function (array $package) use ($input): bool {
8259 );
8360
8461 if ($ outdatedComposer ->count () === 0 ) {
85- $ symfonyStyle ->success ('All packages are up to date ' );
62+ $ this -> symfonyStyle ->success ('All packages are up to date ' );
8663 return self ::SUCCESS ;
8764 }
8865
89- $ symfonyStyle ->title (
66+ $ this -> symfonyStyle ->title (
9067 sprintf (
9168 'Found %d outdated package%s ' ,
9269 $ outdatedComposer ->count ($ onlyDev ),
@@ -95,57 +72,87 @@ static function (array $package) use ($input): bool {
9572 );
9673
9774 foreach ($ outdatedComposer ->getPackages ($ onlyDev ) as $ outdatedPackage ) {
98- $ symfonyStyle ->writeln (
75+ $ this -> symfonyStyle ->writeln (
9976 sprintf ('The "<fg=green>%s</>" package is outdated ' , $ outdatedPackage ->getName ())
10077 );
10178
10279 if ($ outdatedPackage ->getCurrentVersionAge ()) {
103- $ symfonyStyle ->writeln (sprintf (
80+ $ this -> symfonyStyle ->writeln (sprintf (
10481 ' * Your version %s is <fg=%s>%s</> ' ,
10582 $ outdatedPackage ->getCurrentVersion (),
10683 $ outdatedPackage ->isVeryOld () ? 'red ' : 'yellow ' ,
10784 $ outdatedPackage ->getCurrentVersionAge (),
10885 ));
10986 } else {
11087 // composer 2.7- compatible
111- $ symfonyStyle ->writeln (sprintf (' * Your version is %s ' , $ outdatedPackage ->getCurrentVersion ()));
88+ $ this -> symfonyStyle ->writeln (sprintf (' * Your version is %s ' , $ outdatedPackage ->getCurrentVersion ()));
11289 }
11390
114- $ symfonyStyle ->writeln (sprintf (' * Bump to %s ' , $ outdatedPackage ->getLatestVersion ()));
115- $ symfonyStyle ->newLine ();
91+ $ this -> symfonyStyle ->writeln (sprintf (' * Bump to %s ' , $ outdatedPackage ->getLatestVersion ()));
92+ $ this -> symfonyStyle ->newLine ();
11693 }
11794
118- $ symfonyStyle ->newLine ();
95+ $ this -> symfonyStyle ->newLine ();
11996 if ($ outdatedComposer ->count () >= $ maxOutdatePackages ) {
12097 // to much → fail
121- $ symfonyStyle ->error (sprintf (
98+ $ this -> symfonyStyle ->error (sprintf (
12299 'There %s %d outdated package%s. Update couple of them to get under %d limit ' ,
123100 $ outdatedComposer ->count () > 1 ? 'are ' : 'is ' ,
124101 $ outdatedComposer ->count (),
125102 $ outdatedComposer ->count () > 1 ? 's ' : '' ,
126103 $ maxOutdatePackages
127104 ));
128105
129- return self ::FAILURE ;
106+ return ExitCode ::FAILURE ;
130107 }
131108
132109 if ($ outdatedComposer ->count () > max (1 , $ maxOutdatePackages - 5 )) {
133110 // to much → fail
134- $ symfonyStyle ->warning (sprintf (
111+ $ this -> symfonyStyle ->warning (sprintf (
135112 'There are %d outdated packages. Soon, the count will go over %d limit and this job will fail.%sUpgrade in time ' ,
136113 $ outdatedComposer ->count (),
137114 $ maxOutdatePackages ,
138115 PHP_EOL
139116 ));
140117
141- return self ::SUCCESS ;
118+ return ExitCode ::SUCCESS ;
142119 }
143120
144121 // to many → fail
145- $ symfonyStyle ->success (
122+ $ this -> symfonyStyle ->success (
146123 sprintf ('Still far away from limit %d. Good job keeping your project up to date! ' , $ maxOutdatePackages )
147124 );
148125
149- return self ::SUCCESS ;
126+ return ExitCode::SUCCESS ;
127+ }
128+
129+ public function getName (): string
130+ {
131+ return 'breakpoint ' ;
132+ }
133+
134+ public function getDescription (): string
135+ {
136+ return 'Let your CI tell you, if there is too many major-version outdated packages ' ;
137+ }
138+
139+ private function configure (): void
140+ {
141+ $ this ->addOption ('dev ' , null , InputOption::VALUE_NONE , 'Focus on dev packages only ' );
142+
143+ $ this ->addOption (
144+ 'limit ' ,
145+ null ,
146+ InputOption::VALUE_REQUIRED ,
147+ 'Maximum number of outdated major version packages ' ,
148+ 5
149+ );
150+
151+ $ this ->addOption (
152+ 'ignore ' ,
153+ null ,
154+ InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL ,
155+ 'Ignore packages by name, e.g. "symfony/" or "symfony/console" ' ,
156+ );
150157 }
151158}
0 commit comments