Skip to content

Commit a40e54d

Browse files
committed
Adding an age filter to the breakpoint command
1 parent 5569735 commit a40e54d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/Command/BreakPointCommand.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public function __construct(
2424
/**
2525
* @param bool $dev Focus on dev packages only
2626
* @param int $limit Maximum number of outdated major version packages
27+
* @param int $minDays Minimum number of days a release has to be old to be considered outdated
2728
* @param string[] $ignore Ignore packages by name, e.g. "symfony/" or "symfony/console"
2829
*/
29-
public function run(bool $dev = false, int $limit = 5, array $ignore = []): int
30+
public function run(bool $dev = false, int $limit = 5, int $minDays = 0, array $ignore = []): int
3031
{
3132
$this->outputPrinter->green('Analyzing "composer.json" for major outdated packages');
3233

@@ -40,16 +41,26 @@ public function run(bool $dev = false, int $limit = 5, array $ignore = []): int
4041
}
4142

4243
$composerJsonFilePath = getcwd() . '/composer.json';
44+
$now = new \DateTimeImmutable();
4345
$outdatedComposer = $this->outdatedComposerFactory->createOutdatedComposer(
4446
array_filter(
4547
$responseJson[ComposerKey::INSTALLED_KEY],
46-
static function (array $package) use ($ignore): bool {
48+
static function (array $package) use ($ignore, $minDays, $now): bool {
4749
foreach ($ignore as $ignoredPackage) {
4850
if (str_contains((string) $package['name'], $ignoredPackage)) {
4951
return false;
5052
}
5153
}
5254

55+
if ($minDays === 0) {
56+
return true;
57+
}
58+
59+
$pageAgeInDays = (new \DateTimeImmutable($package['release-date']))->diff($now)->days;
60+
if ($pageAgeInDays < $minDays) {
61+
return false;
62+
}
63+
5364
return true;
5465
}
5566
),

0 commit comments

Comments
 (0)