Skip to content

Commit 13fc389

Browse files
author
Phil Sturgeon
committed
This is why I normally write tests
1 parent c0ef2d6 commit 13fc389

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sturgeon/phparse",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"require-dev": {
55
"php-vcr/php-vcr": "~1.2",
66
"crysalead/kahlan": "~1.2"

src/Info.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,27 @@ public function phpSemanticVersion()
3030
*/
3131
private function normalizeSemVerSuffix(string $version): string
3232
{
33-
if (strpos($version, '-') === true) {
34-
return $version;
33+
foreach (['alpha', 'beta', 'RC'] as $suffix) {
34+
if (stripos($version, $suffix) !== false) {
35+
return str_replace($suffix, "-{$suffix}", $version);
36+
}
3537
}
36-
return str_ireplace(['alpha', 'beta', 'rc'], ['-alpha', '-beta', '-rc'], $version);
38+
// Get rid of any remaining build nonsense
39+
return $this->stripLeftOf($version, '-');
3740
}
3841

3942
private function stripCustomBuilds(string $version): string
4043
{
41-
$fuckTildes = substr($version, strpos($version, '~'));
42-
return substr($version, strpos($version, '+'));
44+
$version = $this->stripLeftOf($version, '~');
45+
$version = $this->stripLeftOf($version, '+');
46+
return $version;
47+
}
48+
49+
private function stripLeftOf(string $subject, string $needle): string
50+
{
51+
52+
return strpos($subject, $needle) === false
53+
? $subject
54+
: substr($subject, 0, strpos($subject, $needle));
4355
}
4456
}

0 commit comments

Comments
 (0)