Skip to content

Commit a2b9f27

Browse files
committed
try entropy
1 parent e34eccd commit a2b9f27

27 files changed

+211
-365
lines changed

.github/workflows/bare_run.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
php-version: ${{ matrix.php }}
2121
coverage: none
2222

23-
- run: composer require rector/jack --dev --ansi
23+
- run: composer require rector/jack --dev

.github/workflows/code_analysis.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ jobs:
3030

3131
-
3232
name: 'Jack: Outdated Breakpoint'
33-
run: ./bin/jack breakpoint --ansi --limit 3
33+
run: ./bin/jack breakpoint --limit 3
3434

3535
-
3636
name: 'Jack: Open Versions'
37-
run: ./bin/jack open-versions --dry-run --ansi
37+
run: ./bin/jack open-versions --dry-run
3838

3939
-
4040
name: 'Tests'
4141
run: vendor/bin/phpunit
4242

4343
-
4444
name: 'Check Active Classes'
45-
run: vendor/bin/class-leak check bin src tests --ansi
45+
run: vendor/bin/class-leak check bin src tests --ansi --skip-type="\Entropy\Console\Contract\CommandInterface"
4646

4747
-
4848
name: 'Unusued check'
@@ -56,7 +56,7 @@ jobs:
5656
# see https://github.com/shivammathur/setup-php
5757
- uses: shivammathur/setup-php@v2
5858
with:
59-
php-version: 8.2
59+
php-version: 8.3
6060
coverage: none
6161

6262
# composer install cache - https://github.com/ramsey/composer-install

.github/workflows/downgraded_release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
-
2020
uses: "shivammathur/setup-php@v2"
2121
with:
22-
php-version: 8.2
22+
php-version: 8.3
2323
coverage: none
2424

2525
# invoke patches

bin/jack.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
declare(strict_types=1);
44

5-
use Symfony\Component\Console\Application;
6-
use Symfony\Component\Console\Input\ArgvInput;
7-
use Symfony\Component\Console\Output\ConsoleOutput;
5+
use Entropy\Console\ConsoleApplication;
86
use Rector\Jack\DependencyInjection\ContainerFactory;
97

108
$scoperAutoloadFilepath = __DIR__ . '/../vendor/scoper-autoload.php';
@@ -32,7 +30,7 @@
3230
$containerFactory = new ContainerFactory();
3331
$container = $containerFactory->create();
3432

35-
$application = $container->make(Application::class);
33+
$consoleApplication = $container->make(ConsoleApplication::class);
3634

37-
$exitCode = $application->run(new ArgvInput(), new ConsoleOutput());
35+
$exitCode = $consoleApplication->run($argv);
3836
exit($exitCode);

composer.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
"bin/jack"
77
],
88
"require": {
9-
"php": ">=8.2",
9+
"php": ">=8.3",
1010
"composer/semver": "^3.4",
11-
"illuminate/container": "^12.37",
11+
"entropy/entropy": "dev-main",
1212
"nette/utils": "^4.0",
13-
"symfony/console": "^6.4",
14-
"symfony/finder": "^7.3",
15-
"symfony/process": "^7.3",
16-
"webmozart/assert": "^1.12"
13+
"symfony/process": "^7.4",
14+
"webmozart/assert": "^1.12|^2.0"
1715
},
1816
"require-dev": {
1917
"phpstan/extension-installer": "^1.4",
@@ -23,7 +21,6 @@
2321
"shipmonk/composer-dependency-analyser": "^1.8",
2422
"phpecs/phpecs": "^2.2",
2523
"symplify/phpstan-extensions": "^12.0",
26-
"symplify/vendor-patches": "^11.5",
2724
"tomasvotruba/class-leak": "^2.0",
2825
"tracy/tracy": "^2.11"
2926
},
@@ -41,7 +38,6 @@
4138
"sort-packages": true,
4239
"platform-check": false,
4340
"allow-plugins": {
44-
"cweagans/composer-patches": true,
4541
"phpstan/extension-installer": true
4642
}
4743
},

src/Command/BreakPointCommand.php

Lines changed: 51 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,47 @@
44

55
namespace Rector\Jack\Command;
66

7+
use Entropy\Console\Contract\CommandInterface;
8+
use Entropy\Console\Enum\ExitCode;
9+
use Entropy\Console\Output\OutputPrinter;
710
use Nette\Utils\Json;
811
use Rector\Jack\Composer\ComposerOutdatedResponseProvider;
912
use Rector\Jack\Enum\ComposerKey;
1013
use Rector\Jack\OutdatedComposerFactory;
11-
use Symfony\Component\Console\Command\Command;
12-
use Symfony\Component\Console\Input\InputInterface;
13-
use Symfony\Component\Console\Input\InputOption;
14-
use Symfony\Component\Console\Output\OutputInterface;
15-
use Symfony\Component\Console\Style\SymfonyStyle;
1614

17-
final class BreakPointCommand extends Command
15+
final readonly class BreakPointCommand implements CommandInterface
1816
{
1917
public function __construct(
20-
private readonly OutdatedComposerFactory $outdatedComposerFactory,
21-
private readonly ComposerOutdatedResponseProvider $composerOutdatedResponseProvider
18+
private OutdatedComposerFactory $outdatedComposerFactory,
19+
private ComposerOutdatedResponseProvider $composerOutdatedResponseProvider,
20+
private OutputPrinter $outputPrinter,
2221
) {
23-
parent::__construct();
2422
}
2523

26-
protected function configure(): void
24+
/**
25+
* @param bool $dev Focus on dev packages only
26+
* @param int $limit Maximum number of outdated major version packages
27+
* @param string[] $ignore Ignore packages by name, e.g. "symfony/" or "symfony/console"
28+
*/
29+
public function run(bool $dev = false, int $limit = 5, array $ignore = []): int
2730
{
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);
52-
53-
$maxOutdatePackages = (int) $input->getOption('limit');
54-
$onlyDev = (bool) $input->getOption('dev');
55-
56-
$symfonyStyle->writeln('<fg=green>Analyzing "composer.json" for major outdated packages</>');
31+
$this->outputPrinter->green('Analyzing "composer.json" for major outdated packages');
5732

5833
$responseJsonContents = $this->composerOutdatedResponseProvider->provide();
5934

6035
$responseJson = Json::decode($responseJsonContents, true);
6136
if (! isset($responseJson[ComposerKey::INSTALLED_KEY])) {
62-
$symfonyStyle->success('All packages are up to date');
37+
$this->outputPrinter->green('All packages are up to date');
6338

64-
return self::SUCCESS;
39+
return ExitCode::SUCCESS;
6540
}
6641

6742
$composerJsonFilePath = getcwd() . '/composer.json';
6843
$outdatedComposer = $this->outdatedComposerFactory->createOutdatedComposer(
6944
array_filter(
7045
$responseJson[ComposerKey::INSTALLED_KEY],
71-
static function (array $package) use ($input): bool {
72-
foreach ($input->getOption('ignore') as $ignoredPackage) {
46+
static function (array $package) use ($ignore): bool {
47+
foreach ($ignore as $ignoredPackage) {
7348
if (str_contains((string) $package['name'], $ignoredPackage)) {
7449
return false;
7550
}
@@ -82,70 +57,80 @@ static function (array $package) use ($input): bool {
8257
);
8358

8459
if ($outdatedComposer->count() === 0) {
85-
$symfonyStyle->success('All packages are up to date');
86-
return self::SUCCESS;
60+
$this->outputPrinter->greenBackground('All packages are up to date');
61+
return ExitCode::SUCCESS;
8762
}
8863

89-
$symfonyStyle->title(
64+
$this->outputPrinter->green(
9065
sprintf(
9166
'Found %d outdated package%s',
92-
$outdatedComposer->count($onlyDev),
93-
$outdatedComposer->count($onlyDev) > 1 ? 's' : ''
67+
$outdatedComposer->count($dev),
68+
$outdatedComposer->count($dev) > 1 ? 's' : ''
9469
)
9570
);
9671

97-
foreach ($outdatedComposer->getPackages($onlyDev) as $outdatedPackage) {
98-
$symfonyStyle->writeln(
72+
foreach ($outdatedComposer->getPackages($dev) as $outdatedPackage) {
73+
$this->outputPrinter->writeln(
9974
sprintf('The "<fg=green>%s</>" package is outdated', $outdatedPackage->getName())
10075
);
10176

10277
if ($outdatedPackage->getCurrentVersionAge()) {
103-
$symfonyStyle->writeln(sprintf(
78+
$this->outputPrinter->writeln(sprintf(
10479
' * Your version %s is <fg=%s>%s</>',
10580
$outdatedPackage->getCurrentVersion(),
10681
$outdatedPackage->isVeryOld() ? 'red' : 'yellow',
10782
$outdatedPackage->getCurrentVersionAge(),
10883
));
10984
} else {
11085
// composer 2.7- compatible
111-
$symfonyStyle->writeln(sprintf(' * Your version is %s', $outdatedPackage->getCurrentVersion()));
86+
$this->outputPrinter->writeln(sprintf(' * Your version is %s', $outdatedPackage->getCurrentVersion()));
11287
}
11388

114-
$symfonyStyle->writeln(sprintf(' * Bump to %s', $outdatedPackage->getLatestVersion()));
115-
$symfonyStyle->newLine();
89+
$this->outputPrinter->writeln(sprintf(' * Bump to %s', $outdatedPackage->getLatestVersion()));
90+
$this->outputPrinter->newLine();
11691
}
11792

118-
$symfonyStyle->newLine();
119-
if ($outdatedComposer->count() >= $maxOutdatePackages) {
93+
$this->outputPrinter->newLine();
94+
if ($outdatedComposer->count() >= $limit) {
12095
// to much → fail
121-
$symfonyStyle->error(sprintf(
96+
$this->outputPrinter->redBackground(sprintf(
12297
'There %s %d outdated package%s. Update couple of them to get under %d limit',
12398
$outdatedComposer->count() > 1 ? 'are' : 'is',
12499
$outdatedComposer->count(),
125100
$outdatedComposer->count() > 1 ? 's' : '',
126-
$maxOutdatePackages
101+
$limit
127102
));
128103

129-
return self::FAILURE;
104+
return ExitCode::ERROR;
130105
}
131106

132-
if ($outdatedComposer->count() > max(1, $maxOutdatePackages - 5)) {
107+
if ($outdatedComposer->count() > max(1, $limit - 5)) {
133108
// to much → fail
134-
$symfonyStyle->warning(sprintf(
109+
$this->outputPrinter->orangeBackground(sprintf(
135110
'There are %d outdated packages. Soon, the count will go over %d limit and this job will fail.%sUpgrade in time',
136111
$outdatedComposer->count(),
137-
$maxOutdatePackages,
112+
$limit,
138113
PHP_EOL
139114
));
140115

141-
return self::SUCCESS;
116+
return ExitCode::SUCCESS;
142117
}
143118

144119
// to many → fail
145-
$symfonyStyle->success(
146-
sprintf('Still far away from limit %d. Good job keeping your project up to date!', $maxOutdatePackages)
120+
$this->outputPrinter->greenBackground(
121+
sprintf('Still far away from limit %d. Good job keeping your project up to date!', $limit)
147122
);
148123

149-
return self::SUCCESS;
124+
return ExitCode::SUCCESS;
125+
}
126+
127+
public function getName(): string
128+
{
129+
return 'breakpoint';
130+
}
131+
132+
public function getDescription(): string
133+
{
134+
return 'Let your CI tell you, if there is too many major-version outdated packages';
150135
}
151136
}

0 commit comments

Comments
 (0)