Skip to content

Commit 5569735

Browse files
authored
try entropy (#33)
1 parent e34eccd commit 5569735

28 files changed

+209
-376
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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,26 @@ jobs:
3030

3131
-
3232
name: 'Jack: Outdated Breakpoint'
33-
run: ./bin/jack breakpoint --ansi --limit 3
33+
run: ./bin/jack breakpoint --limit 3
34+
35+
-
36+
name: "Commented Code"
37+
run: vendor/bin/swiss-knife check-commented-code src tests --ansi
3438

3539
-
3640
name: 'Jack: Open Versions'
37-
run: ./bin/jack open-versions --dry-run --ansi
41+
run: ./bin/jack open-versions --dry-run
3842

3943
-
4044
name: 'Tests'
4145
run: vendor/bin/phpunit
4246

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

4751
-
48-
name: 'Unusued check'
52+
name: 'Composer Dependency Analyser'
4953
run: vendor/bin/composer-dependency-analyser
5054

5155
name: ${{ matrix.actions.name }}
@@ -56,7 +60,7 @@ jobs:
5660
# see https://github.com/shivammathur/setup-php
5761
- uses: shivammathur/setup-php@v2
5862
with:
59-
php-version: 8.2
63+
php-version: 8.3
6064
coverage: none
6165

6266
# 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: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@
66
"bin/jack"
77
],
88
"require": {
9-
"php": ">=8.2",
9+
"php": ">=8.3",
1010
"composer/semver": "^3.4",
11-
"illuminate/container": "^12.37",
12-
"nette/utils": "^4.0",
13-
"symfony/console": "^6.4",
14-
"symfony/finder": "^7.3",
15-
"symfony/process": "^7.3",
16-
"webmozart/assert": "^1.12"
11+
"entropy/entropy": "dev-main",
12+
"nette/utils": "^4.1",
13+
"symfony/process": "^7.4",
14+
"webmozart/assert": "^2.0"
1715
},
1816
"require-dev": {
17+
"phpecs/phpecs": "^2.2",
1918
"phpstan/extension-installer": "^1.4",
2019
"phpstan/phpstan": "^2.1",
21-
"phpunit/phpunit": "^11.5|^12.0",
20+
"phpunit/phpunit": "^12.5",
2221
"rector/rector": "^2.2",
22+
"rector/swiss-knife": "^2.3",
2323
"shipmonk/composer-dependency-analyser": "^1.8",
24-
"phpecs/phpecs": "^2.2",
2524
"symplify/phpstan-extensions": "^12.0",
26-
"symplify/vendor-patches": "^11.5",
27-
"tomasvotruba/class-leak": "^2.0",
25+
"tomasvotruba/class-leak": "^2.1",
2826
"tracy/tracy": "^2.11"
2927
},
3028
"autoload": {
@@ -41,7 +39,6 @@
4139
"sort-packages": true,
4240
"platform-check": false,
4341
"allow-plugins": {
44-
"cweagans/composer-patches": true,
4542
"phpstan/extension-installer": true
4643
}
4744
},

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
instanceOf: true,
1818
naming: true
1919
)
20+
->withSkip([\Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector::class])
2021
->withImportNames(removeUnusedImports: true)
2122
->withSkip(['*/scoper.php', '*/Source/*', '*/Fixture/*']);

src/Command/BreakPointCommand.php

Lines changed: 52 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,81 @@ 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->yellow(
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
);
71+
$this->outputPrinter->newline();
9672

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

10278
if ($outdatedPackage->getCurrentVersionAge()) {
103-
$symfonyStyle->writeln(sprintf(
79+
$this->outputPrinter->writeln(sprintf(
10480
' * Your version %s is <fg=%s>%s</>',
10581
$outdatedPackage->getCurrentVersion(),
10682
$outdatedPackage->isVeryOld() ? 'red' : 'yellow',
10783
$outdatedPackage->getCurrentVersionAge(),
10884
));
10985
} else {
11086
// composer 2.7- compatible
111-
$symfonyStyle->writeln(sprintf(' * Your version is %s', $outdatedPackage->getCurrentVersion()));
87+
$this->outputPrinter->writeln(sprintf(' * Your version is %s', $outdatedPackage->getCurrentVersion()));
11288
}
11389

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

118-
$symfonyStyle->newLine();
119-
if ($outdatedComposer->count() >= $maxOutdatePackages) {
94+
$this->outputPrinter->newLine();
95+
if ($outdatedComposer->count() >= $limit) {
12096
// to much → fail
121-
$symfonyStyle->error(sprintf(
97+
$this->outputPrinter->redBackground(sprintf(
12298
'There %s %d outdated package%s. Update couple of them to get under %d limit',
12399
$outdatedComposer->count() > 1 ? 'are' : 'is',
124100
$outdatedComposer->count(),
125101
$outdatedComposer->count() > 1 ? 's' : '',
126-
$maxOutdatePackages
102+
$limit
127103
));
128104

129-
return self::FAILURE;
105+
return ExitCode::ERROR;
130106
}
131107

132-
if ($outdatedComposer->count() > max(1, $maxOutdatePackages - 5)) {
108+
if ($outdatedComposer->count() > max(1, $limit - 5)) {
133109
// to much → fail
134-
$symfonyStyle->warning(sprintf(
110+
$this->outputPrinter->orangeBackground(sprintf(
135111
'There are %d outdated packages. Soon, the count will go over %d limit and this job will fail.%sUpgrade in time',
136112
$outdatedComposer->count(),
137-
$maxOutdatePackages,
113+
$limit,
138114
PHP_EOL
139115
));
140116

141-
return self::SUCCESS;
117+
return ExitCode::SUCCESS;
142118
}
143119

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

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

0 commit comments

Comments
 (0)