Skip to content

Commit 29d64f5

Browse files
committed
Fixes version object __toString method.
1 parent ce0fa16 commit 29d64f5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"headers"
1515
],
1616
"homepage": "https://github.com/deviscoding/objection",
17-
"version": "1.0",
17+
"version": "1.0.1",
1818
"license": "MIT",
1919
"authors": [
2020
{

src/Object/System/Version/BaseVersion.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
* @author AMJones <am@jonesiscoding.com>
1515
* @license https://github.com/deviscoding/objection/blob/main/LICENSE
16+
*
1617
* @package DevCoding\Object\System\Version
1718
*/
1819
abstract class BaseVersion
@@ -74,23 +75,32 @@ public static function fromArray(array $array)
7475
*/
7576
public function __toString()
7677
{
77-
return implode($this->toArray());
78+
// Start off with major and minor. Methods will return 0 if not set, so we'll always have these.
79+
$str = implode('.', [$this->getMajor(), $this->getMinor()]);
80+
// Add in the patch with the period prefix, if applicable.
81+
$str .= ($patch = $this->getPatch()) ? '.'.$patch : '';
82+
// Add in the prerelease with the dash prefix, if applicable.
83+
$str .= ($pre = $this->getPreRelease()) ? '-'.$pre : '';
84+
// Add in the build with the plus prefix, if applicable.
85+
$str .= ($build = $this->getBuild()) ? '+'.$build : '';
86+
87+
return $str;
7888
}
7989

8090
/**
8191
* @return int
8292
*/
83-
public function getMajor(): int
93+
public function getMajor()
8494
{
85-
return $this->major;
95+
return $this->major ?? 0;
8696
}
8797

8898
/**
8999
* @return int
90100
*/
91101
public function getMinor()
92102
{
93-
return $this->minor;
103+
return $this->minor ?? 0;
94104
}
95105

96106
/**

0 commit comments

Comments
 (0)