Skip to content

Commit

Permalink
feat: Display with which version of Box the PHAR was built (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Oct 22, 2023
1 parent 59d2d4f commit d0a1b4d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Console/Command/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ private static function showPharInfo(

$io->newLine();

PharInfoRenderer::renderBoxVersion($pharInfo, $io);

PharInfoRenderer::renderShortSummary(
$pharInfo,
$io,
Expand Down
30 changes: 30 additions & 0 deletions src/Console/PharInfoRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use function KevinGH\Box\format_size as format_size1;
use function KevinGH\Box\noop;
use function key;
use function preg_match;
use function round;
use function Safe\filesize;
use function sprintf;
Expand All @@ -52,6 +53,7 @@ final class PharInfoRenderer
use NotInstantiable;

private const BOX_REQUIREMENTS = '.box/.requirements.php';
private const BOX_VERSION_PATTERN = '/ \* Generated by Humbug Box (?<version>.+)\.\s/';
private const INDENT_SIZE = 2;

public static function renderShortSummary(
Expand Down Expand Up @@ -91,6 +93,23 @@ public static function renderVersion(PharInfo $pharInfo, IO $io): void
);
}

public static function renderBoxVersion(PharInfo $pharInfo, IO $io): void
{
$version = self::extractBoxVersion($pharInfo);

if (null === $version) {
return;
}

$io->writeln(
sprintf(
'<comment>Built with Box:</comment> %s',
$version,
),
);
$io->newLine();
}

public static function renderCompression(PharInfo $pharInfo, IO $io): void
{
$io->writeln(
Expand Down Expand Up @@ -296,6 +315,17 @@ public static function renderContent(
}
}

private static function extractBoxVersion(PharInfo $pharInfo): ?string
{
$stub = $pharInfo->getStubContent();

if (null !== $stub && 1 === preg_match(self::BOX_VERSION_PATTERN, $stub, $matches)) {
return $matches['version'];
}

return null;
}

/**
* @return array{Requirement[], Requirement[]}
*/
Expand Down
16 changes: 16 additions & 0 deletions tests/Console/Command/InfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b2c33cd
Archive Compression: None
Files Compression: None
Expand Down Expand Up @@ -669,6 +671,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b2c33cd
Archive Compression: None
Files Compression: None
Expand Down Expand Up @@ -698,6 +702,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b7472c2
Archive Compression: None
Files Compression: None
Expand All @@ -724,6 +730,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b2c33cd
Archive Compression: None
Files Compression: None
Expand Down Expand Up @@ -752,6 +760,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b2c33cd
Archive Compression: None
Files Compression: None
Expand Down Expand Up @@ -780,6 +790,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b2c33cd
Archive Compression: None
Files Compression: None
Expand Down Expand Up @@ -808,6 +820,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b2c33cd
Archive Compression: None
Files Compression: None
Expand Down Expand Up @@ -837,6 +851,8 @@ public static function inputProvider(): iterable
API Version: 1.1.0
Built with Box: dev-main@b2c33cd
Archive Compression: None
Files Compression: None
Expand Down

0 comments on commit d0a1b4d

Please sign in to comment.