Skip to content

Commit 2e69ebd

Browse files
authored
make version age compatbile with composer 2.7 (#12)
1 parent ba53887 commit 2e69ebd

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/Command/BreakPointCommand.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7676
sprintf('The "<fg=green>%s</>" package is outdated', $outdatedPackage->getName())
7777
);
7878

79-
$symfonyStyle->writeln(sprintf(
80-
' * Your version %s is <fg=%s>%s</>',
81-
$outdatedPackage->getCurrentVersion(),
82-
$outdatedPackage->isVeryOld() ? 'red' : 'yellow',
83-
$outdatedPackage->getCurrentVersionAge(),
84-
));
79+
if ($outdatedPackage->getCurrentVersionAge()) {
80+
$symfonyStyle->writeln(sprintf(
81+
' * Your version %s is <fg=%s>%s</>',
82+
$outdatedPackage->getCurrentVersion(),
83+
$outdatedPackage->isVeryOld() ? 'red' : 'yellow',
84+
$outdatedPackage->getCurrentVersionAge(),
85+
));
86+
} else {
87+
// composer 2.7- compatible
88+
$symfonyStyle->writeln(sprintf(' * Your version is %s', $outdatedPackage->getCurrentVersion()));
89+
}
8590

8691
$symfonyStyle->writeln(sprintf(' * Bump to %s', $outdatedPackage->getLatestVersion()));
8792
$symfonyStyle->newLine();

src/Mapper/OutdatedPackageMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function mapToObjects(array $outdatedPackages, string $composerJsonFilePa
3232
$composerVersions,
3333
$isProd,
3434
$data['latest'],
35-
$data['release-age']
35+
$data['release-age'] ?? null
3636
);
3737
}, $outdatedPackages);
3838
}

src/ValueObject/OutdatedPackage.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public function __construct(
1414
private string $composerVersion,
1515
private bool $isProd,
1616
private string $latestVersion,
17-
private string $currentVersionAge,
17+
// nullable on composer 2.7-
18+
private ?string $currentVersionAge,
1819
) {
1920
}
2021

@@ -43,13 +44,17 @@ public function getLatestVersion(): string
4344
return $this->latestVersion;
4445
}
4546

46-
public function getCurrentVersionAge(): string
47+
public function getCurrentVersionAge(): ?string
4748
{
4849
return $this->currentVersionAge;
4950
}
5051

5152
public function isVeryOld(): bool
5253
{
54+
if ($this->currentVersionAge === null) {
55+
return true;
56+
}
57+
5358
$matchYears = Strings::match($this->currentVersionAge, '#[3-9] years#');
5459
return $matchYears !== null;
5560
}

0 commit comments

Comments
 (0)