Skip to content

Commit

Permalink
fix(semver): add get version code method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed May 14, 2021
1 parent cb57a6e commit 54599fb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Helper/SemanticVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class SemanticVersion
*/
public const PATTERN = '([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?';

/**
* Pattern no extra.
*
* @var string
*/
public const PATTERN_NO_EXTRA = '([0-9]+)\.([0-9]+)\.([0-9]+)';

/**
* @var string
*/
Expand Down Expand Up @@ -114,6 +121,15 @@ public function getVersion(): string
return $this->version;
}

public function getVersionCode(): string
{
if (preg_match('/' . self::PATTERN_NO_EXTRA . '/', $this->version, $match)) {
return $match[0];
}

return '0.0.0';
}

public function setVersion(string $version): SemanticVersion
{
$this->version = $version;
Expand Down

0 comments on commit 54599fb

Please sign in to comment.