Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Display with which version of Box the PHAR was built #1116

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading