Skip to content

Commit

Permalink
Adjust Utils::getVersion to return null if version is not found (#193)
Browse files Browse the repository at this point in the history
This commit updates the Utils::getVersion method to return null when the
version file is not found, instead of a string error message.
  • Loading branch information
SmetDenis authored May 9, 2024
1 parent a0a6637 commit 5e2ab06
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion csv-blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@

Utils::init();

(new CliApplication('CSV Blueprint', Utils::getVersion(true)))
(new CliApplication('CSV Blueprint', (string)Utils::getVersion(true)))
->registerCommandsByPath(PATH_ROOT . '/src/Commands', __NAMESPACE__)
->run();
3 changes: 2 additions & 1 deletion src/CliApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ final class CliApplication extends \JBZoo\Cli\CliApplication
public function getLongVersion(): string
{
$logo = '<info>' . \implode("</info>\n<info>", $this->appLogo) . '</info>';
$version = Utils::getVersion(true);

return "{$logo}\n" . Utils::getVersion(true);
return $version === null ? $logo : "{$logo}\n{$version}";
}
}
5 changes: 4 additions & 1 deletion src/Commands/AbstractValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ protected function preparation(bool $showIntro = true): void
{
if ($showIntro) {
if ($this->isHumanReadableMode()) {
$this->_('CSV Blueprint: ' . Utils::getVersion(true));
$version = Utils::getVersion(true);
if ($version !== null) {
$this->_("CSV Blueprint: {$version}");
}
}

$threads = $this->getNumberOfThreads();
Expand Down
10 changes: 5 additions & 5 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,19 @@ public static function printFile(string $fullpath, string $tag = 'bright-blue'):

/**
* Retrieves the version of the software.
* @param bool $showFull Whether to display the full version information or not. Default is false.
* @return string the version of the software as a string, or an error message if the version file is
* not found
* @param bool $showFull Whether to display the full version information or not. Default is false.
* @return null|string the version of the software as a string, or an error message if the version file is
* not found
*/
public static function getVersion(bool $showFull): string
public static function getVersion(bool $showFull): ?string
{
if (self::isPhpUnit()) {
return 'Unknown version (PhpUnit)';
}

$versionFile = __DIR__ . '/../.version';
if (!\file_exists($versionFile)) {
return 'Version file not found';
return null;
}

return self::parseVersion((string)\file_get_contents($versionFile), $showFull);
Expand Down

0 comments on commit 5e2ab06

Please sign in to comment.