Skip to content

Commit c0ef2d6

Browse files
author
Phil Sturgeon
committed
Fixed beta/RC versions
1 parent 5245b47 commit c0ef2d6

5 files changed

Lines changed: 31 additions & 28 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.1.0",
3+
"version": "0.2.0",
44
"require-dev": {
55
"php-vcr/php-vcr": "~1.2",
66
"crysalead/kahlan": "~1.2"

kahlan-config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?php
2-
use filter\Filter;
1+
<?php
2+
use kahlan\filter\Filter;
33
use VCR\VCR;
44

55
VCR::configure()->setCassettePath(__DIR__.'/spec/fixtures');

spec/ParserSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
});
1515

1616
beforeEach(function() {
17-
$url = 'http://localhost:8000/?version=5.6.12';
17+
$url = 'http://localhost:8000/?version=7.0.11';
1818
$this->parser = Parser::readFromUrl($url);
1919
});
2020

spec/fixtures/phpinfos

Lines changed: 3 additions & 21 deletions
Large diffs are not rendered by default.

src/Info.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Info
66
{
7-
public function __construct($version, array $infoItems = [])
7+
public function __construct(string $version, array $infoItems = [])
88
{
99
$this->version = $version;
1010
$this->infoItems = $infoItems;
@@ -17,7 +17,28 @@ public function phpVersion()
1717

1818
public function phpSemanticVersion()
1919
{
20-
$noSuffix = (array) explode('-', $this->version);
21-
return SemVerParser::parse($noSuffix[0]);
20+
return SemVerParser::parse(
21+
$this->normalizeSemVerSuffix(
22+
$this->stripCustomBuilds($this->version)
23+
)
24+
);
25+
}
26+
27+
/**
28+
* PHP releases use SemVer numbers, but the format is a bit out of whack with
29+
* the usual vx.y.z-beta1 style SemVer parser expects.
30+
*/
31+
private function normalizeSemVerSuffix(string $version): string
32+
{
33+
if (strpos($version, '-') === true) {
34+
return $version;
35+
}
36+
return str_ireplace(['alpha', 'beta', 'rc'], ['-alpha', '-beta', '-rc'], $version);
37+
}
38+
39+
private function stripCustomBuilds(string $version): string
40+
{
41+
$fuckTildes = substr($version, strpos($version, '~'));
42+
return substr($version, strpos($version, '+'));
2243
}
2344
}

0 commit comments

Comments
 (0)