Skip to content

Commit 9c3272d

Browse files
committed
- refactor get_complete_version() for VERSION file and $version argument
1 parent 9342c8a commit 9c3272d

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

semver.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,14 @@ function get_version_array(string $version): array
6161
*/
6262
function get_complete_version(array $version): array
6363
{
64-
if (false === empty($version)) {
65-
goto assert;
64+
if (empty($version)) {
65+
$version = match (true) {
66+
defined('VERSION') && is_array(VERSION) => get_version_array(join('-', array_filter(VERSION))),
67+
file_exists($version = __DIR__ . '/../../../VERSION'), // project dir relative to /vendor
68+
file_exists($version = getcwd() . '/VERSION') => get_version_array(@file_get_contents($version)),
69+
default => INVALID_VERSION_ARRAY,
70+
};
6671
}
67-
$version = match (true) {
68-
defined('VERSION') && is_array(VERSION) => get_version_array(join('-', array_filter(VERSION))),
69-
file_exists($version = __DIR__ . '/../../../VERSION'), // project dir relative to vendor
70-
file_exists($version = getcwd() . '/VERSION') => get_version_array(@file_get_contents($version)),
71-
default => INVALID_VERSION_ARRAY,
72-
};
73-
assert:
7472
assert(3 === count($version), 'version array should have exactly 3 parts');
7573
assert('' !== $version[1], 'pre-release is empty, should be zero or valid identifier');
7674
assert('' !== $version[2], 'build-metadata is empty, should be zero or valid identifier');

0 commit comments

Comments
 (0)