Skip to content

Commit 049a1d8

Browse files
committed
Squashed commit of the following:
commit fc25e8f Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Mon Apr 1 18:12:50 2024 +0200 Update README.md commit aa964fd Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Mon Apr 1 17:56:40 2024 +0200 Update Version.php commit 9e3303a Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 23:23:21 2024 +0200 Update README.md commit dda776a Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 22:29:48 2024 +0200 Update ci.yml commit f3f6319 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 22:26:31 2024 +0200 Fix report errors commit 2050543 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 22:23:05 2024 +0200 Reformat, fix phpunit execution commit 5b1a770 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 22:12:08 2024 +0200 Update composer.json commit 23e2e63 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 21:48:12 2024 +0200 Add tests report commit 9c90e15 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 21:38:38 2024 +0200 Add sonarcloud analysis commit eb9141a Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Mar 31 21:15:45 2024 +0200 Update to PHP 8
1 parent 0c08e4f commit 049a1d8

27 files changed

+235
-309
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
16+
php-versions: [ '8.1', '8.2', '8.3' ]
1717
steps:
1818
- uses: actions/checkout@v4
1919

@@ -41,17 +41,18 @@ jobs:
4141
- name: Execute tests
4242
run: vendor/bin/phpunit
4343

44-
45-
coverage:
44+
analysis:
4645
needs: [test]
4746
runs-on: ubuntu-latest
4847
steps:
4948
- uses: actions/checkout@v4
49+
with:
50+
fetch-depth: 0
5051

5152
- name: Setup PHP
5253
uses: shivammathur/setup-php@v2
5354
with:
54-
php-version: '7.4'
55+
php-version: '8.1'
5556
extensions: xdebug
5657

5758
- name: Validate composer.json and composer.lock
@@ -71,10 +72,14 @@ jobs:
7172
composer install --prefer-dist --no-progress --no-suggest
7273
7374
- name: Execute coverage
74-
run: vendor/bin/phpunit --coverage-clover clover.xml
75+
run: vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=tests.xml
76+
env:
77+
XDEBUG_MODE: coverage
7578

76-
- name: Upload coverage report
77-
run: bash <(curl -s https://codecov.io/bash)
79+
- name: SonarCloud Scan
80+
uses: SonarSource/sonarcloud-github-action@master
81+
env:
82+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7883

7984
php-cs-fixer:
8085
runs-on: ubuntu-latest
@@ -84,7 +89,7 @@ jobs:
8489
- name: Setup PHP
8590
uses: shivammathur/setup-php@v2
8691
with:
87-
php-version: '7.4'
92+
php-version: '8.1'
8893
ini-values: 'memory_limit=-1'
8994

9095
- name: Validate composer.json and composer.lock
@@ -114,7 +119,7 @@ jobs:
114119
- name: Setup PHP
115120
uses: shivammathur/setup-php@v2
116121
with:
117-
php-version: '7.4'
122+
php-version: '8.1'
118123
ini-values: 'memory_limit=-1'
119124

120125
- name: Validate composer.json and composer.lock

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# php-semver
22
[![Build Status](https://github.com/z4kn4fein/php-semver/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/z4kn4fein/php-semver/actions/workflows/ci.yml)
3-
[![Coverage Status](https://img.shields.io/codecov/c/github/z4kn4fein/php-semver.svg)](https://codecov.io/gh/z4kn4fein/php-semver)
43
[![Latest Stable Version](https://poser.pugx.org/z4kn4fein/php-semver/version)](https://packagist.org/packages/z4kn4fein/php-semver)
54
[![Total Downloads](https://poser.pugx.org/z4kn4fein/php-semver/downloads)](https://packagist.org/packages/z4kn4fein/php-semver)
6-
[![Latest Unstable Version](https://poser.pugx.org/z4kn4fein/php-semver/v/unstable)](https://packagist.org/packages/z4kn4fein/php-semver)
5+
[![Sonar Quality Gate](https://img.shields.io/sonar/quality_gate/z4kn4fein_php-semver?logo=sonarcloud&server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/project/overview?id=z4kn4fein_php-semver)
6+
[![Sonar Coverage](https://img.shields.io/sonar/coverage/z4kn4fein_php-semver?logo=SonarCloud&server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/project/overview?id=z4kn4fein_php-semver)
77

88
Semantic Versioning library for PHP. It implements the full [semantic version 2.0.0](https://semver.org/spec/v2.0.0.html) specification and
99
provides ability to **parse**, **compare**, and **increment** semantic versions along with validation against **constraints**.
1010

1111
## Requirements
12-
[PHP](https://www.php.net/) >= 7.1
12+
| Version | PHP Version |
13+
|---------------|-------------|
14+
| `>=1.0, <1.2` | >=5.5 |
15+
| `>=1.2, <3.0` | >=7.1 |
16+
| `>=3.0` | >=8.1 |
17+
1318

1419
## Install with [Composer](https://getcomposer.org/)
1520
```shell

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=7.1"
16+
"php": ">=8.1"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^7|^8",
19+
"phpunit/phpunit": "^10",
2020
"phpstan/phpstan": "^1.0",
2121
"friendsofphp/php-cs-fixer": "^3.0"
2222
},

phpunit.xml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
<phpunit
2-
backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
beStrictAboutTestsThatDoNotTestAnything="true"
10-
beStrictAboutOutputDuringTests="true"
11-
processIsolation="false"
12-
stopOnFailure="false">
13-
<testsuites>
14-
<testsuite name="Unit Tests">
15-
<directory>tests</directory>
16-
</testsuite>
17-
</testsuites>
18-
<filter>
19-
<whitelist processUncoveredFilesFromWhitelist="true">
20-
<directory suffix=".php">src</directory>
21-
</whitelist>
22-
</filter>
23-
</phpunit>
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Unit Tests">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">src</directory>
11+
</include>
12+
</source>
13+
</phpunit>

sonar-project.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sonar.projectKey=z4kn4fein_php-semver
2+
sonar.organization=z4kn4fein
3+
sonar.sources=src
4+
sonar.tests=tests
5+
6+
sonar.php.tests.reportPath=tests.xml
7+
sonar.php.coverage.reportPaths=coverage.xml

src/Constraints/Condition.php

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace z4kn4fein\SemVer\Constraints;
46

57
use z4kn4fein\SemVer\SemverException;
@@ -13,11 +15,8 @@ class Condition implements VersionComparator
1315
{
1416
use Singles;
1517

16-
/** @var string */
17-
private $operator;
18-
19-
/** @var Version */
20-
private $version;
18+
private string $operator;
19+
private Version $version;
2120

2221
public function __construct(string $operator, Version $version)
2322
{
@@ -38,61 +37,31 @@ public function __toString(): string
3837
*/
3938
public function isSatisfiedBy(Version $version): bool
4039
{
41-
switch ($this->operator) {
42-
case Op::EQUAL:
43-
return $version->isEqual($this->version);
44-
45-
case Op::NOT_EQUAL:
46-
return !$version->isEqual($this->version);
47-
48-
case Op::LESS_THAN:
49-
return $version->isLessThan($this->version);
50-
51-
case Op::LESS_THAN_OR_EQUAL:
52-
case Op::LESS_THAN_OR_EQUAL2:
53-
return $version->isLessThanOrEqual($this->version);
54-
55-
case Op::GREATER_THAN:
56-
return $version->isGreaterThan($this->version);
57-
58-
case Op::GREATER_THAN_OR_EQUAL:
59-
case Op::GREATER_THAN_OR_EQUAL2:
60-
return $version->isGreaterThanOrEqual($this->version);
61-
62-
default:
63-
throw new SemverException(sprintf('Invalid operator in condition %s', (string) $this));
64-
}
40+
return match ($this->operator) {
41+
Op::EQUAL => $version->isEqual($this->version),
42+
Op::NOT_EQUAL => !$version->isEqual($this->version),
43+
Op::LESS_THAN => $version->isLessThan($this->version),
44+
Op::LESS_THAN_OR_EQUAL, Op::LESS_THAN_OR_EQUAL2 => $version->isLessThanOrEqual($this->version),
45+
Op::GREATER_THAN => $version->isGreaterThan($this->version),
46+
Op::GREATER_THAN_OR_EQUAL, Op::GREATER_THAN_OR_EQUAL2 => $version->isGreaterThanOrEqual($this->version),
47+
default => throw new SemverException(sprintf('Invalid operator in condition %s', $this)),
48+
};
6549
}
6650

6751
/**
6852
* @throws SemverException
6953
*/
7054
public function opposite(): string
7155
{
72-
switch ($this->operator) {
73-
case Op::EQUAL:
74-
return Op::NOT_EQUAL.$this->version;
75-
76-
case Op::NOT_EQUAL:
77-
return Op::EQUAL.$this->version;
78-
79-
case Op::LESS_THAN:
80-
return Op::GREATER_THAN_OR_EQUAL.$this->version;
81-
82-
case Op::LESS_THAN_OR_EQUAL:
83-
case Op::LESS_THAN_OR_EQUAL2:
84-
return Op::GREATER_THAN.$this->version;
85-
86-
case Op::GREATER_THAN:
87-
return Op::LESS_THAN_OR_EQUAL.$this->version;
88-
89-
case Op::GREATER_THAN_OR_EQUAL:
90-
case Op::GREATER_THAN_OR_EQUAL2:
91-
return Op::LESS_THAN.$this->version;
92-
93-
default:
94-
throw new SemverException(sprintf('Invalid operator in condition %s', (string) $this));
95-
}
56+
return match ($this->operator) {
57+
Op::EQUAL => Op::NOT_EQUAL.$this->version,
58+
Op::NOT_EQUAL => Op::EQUAL.$this->version,
59+
Op::LESS_THAN => Op::GREATER_THAN_OR_EQUAL.$this->version,
60+
Op::LESS_THAN_OR_EQUAL, Op::LESS_THAN_OR_EQUAL2 => Op::GREATER_THAN.$this->version,
61+
Op::GREATER_THAN => Op::LESS_THAN_OR_EQUAL.$this->version,
62+
Op::GREATER_THAN_OR_EQUAL, Op::GREATER_THAN_OR_EQUAL2 => Op::LESS_THAN.$this->version,
63+
default => throw new SemverException(sprintf('Invalid operator in condition %s', $this)),
64+
};
9665
}
9766

9867
public static function greaterThanMin(): Condition

src/Constraints/Constraint.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace z4kn4fein\SemVer\Constraints;
46

57
use Exception;
@@ -21,7 +23,7 @@ class Constraint
2123
use Validator;
2224

2325
/** @var VersionComparator[][] */
24-
private $comparators;
26+
private array $comparators;
2527

2628
/**
2729
* @param VersionComparator[][] $comparators
@@ -82,7 +84,7 @@ public static function parseOrNull(string $constraintString): ?Constraint
8284
{
8385
try {
8486
return self::parse($constraintString);
85-
} catch (Exception $exception) {
87+
} catch (Exception) {
8688
return null;
8789
}
8890
}
@@ -92,9 +94,9 @@ public static function parseOrNull(string $constraintString): ?Constraint
9294
*
9395
* @param string $constraintString the string to parse
9496
*
95-
* @throws SemverException when the constraint string is invalid
96-
*
9797
* @return Constraint the parsed constraint
98+
*
99+
* @throws SemverException when the constraint string is invalid
98100
*/
99101
public static function parse(string $constraintString): Constraint
100102
{
@@ -152,7 +154,7 @@ function ($matches) use (&$result) {
152154
}
153155

154156
/**
155-
* @param mixed[] $matches
157+
* @param string[] $matches
156158
*
157159
* @throws SemverException
158160
*/
@@ -181,7 +183,7 @@ private static function hyphenToComparator(array $matches): VersionComparator
181183
}
182184

183185
/**
184-
* @param mixed[] $matches
186+
* @param string[] $matches
185187
*
186188
* @throws SemverException
187189
*/

src/Constraints/Op.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace z4kn4fein\SemVer\Constraints;
46

57
/**

0 commit comments

Comments
 (0)