Skip to content

Commit d9d645c

Browse files
committed
Additional error handling for SemanticVersions
1 parent bb4489c commit d9d645c

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"email": "am@jonesiscoding.com"
1010
}
1111
],
12-
"version": "1.5",
12+
"version": "1.5.1",
1313
"autoload": {
1414
"psr-4": {
1515
"DevCoding\\Mac\\": "src"

src/Objects/MacApplication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getShortVersion()
5656
{
5757
try
5858
{
59-
return SemanticVersion::parse($this->getPlistValue('CFBundleShortVersionString'));
59+
return new SemanticVersion($this->getPlistValue('CFBundleShortVersionString'));
6060
}
6161
catch (\Exception $e)
6262
{
@@ -71,7 +71,7 @@ public function getVersion()
7171
{
7272
try
7373
{
74-
return SemanticVersion::parse($this->getPlistValue('CFBundleVersion'));
74+
return new SemanticVersion($this->getPlistValue('CFBundleVersion'));
7575
}
7676
catch (\Exception $e)
7777
{

src/Objects/SemanticVersion.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,33 @@
66

77
class SemanticVersion extends Version
88
{
9+
protected $raw;
10+
911
public function __construct(string $version = '0.1.0')
1012
{
13+
$this->raw = $version;
14+
1115
try
1216
{
1317
parent::__construct($version);
1418
}
1519
catch (\Exception $e)
1620
{
17-
$Fix = static::parse($version);
21+
try
22+
{
23+
// Try the built in fixer
24+
$Fix = static::parse($version);
25+
}
26+
catch (\Exception $e)
27+
{
28+
// Too many dots
29+
$v = explode('.', $version);
30+
if (count($v) > 3)
31+
{
32+
$version = array_shift($v) . "." . array_shift($v) . '.' . implode('', $v);
33+
$Fix = static::parse($version);
34+
}
35+
}
1836

1937
$this->setMajor($Fix->major);
2038
$this->setMinor($Fix->minor);
@@ -24,6 +42,11 @@ public function __construct(string $version = '0.1.0')
2442
}
2543
}
2644

45+
public function getRaw()
46+
{
47+
return $this->raw;
48+
}
49+
2750
public function getBuild()
2851
{
2952
return $this->build;

0 commit comments

Comments
 (0)