Skip to content

Commit

Permalink
Reformat, fix phpunit execution
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Mar 31, 2024
1 parent 5b1a770 commit 2050543
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jobs:
- name: Execute coverage
run: vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=tests.xml
env:
XDEBUG_MODE: coverage

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
Expand Down
36 changes: 13 additions & 23 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
<?xml version="1.0"?>
<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">
<testsuites>
<testsuite name="Unit Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public static function parseOrNull(string $constraintString): ?Constraint
*
* @param string $constraintString the string to parse
*
* @throws SemverException when the constraint string is invalid
*
* @return Constraint the parsed constraint
*
* @throws SemverException when the constraint string is invalid
*/
public static function parse(string $constraintString): Constraint
{
Expand Down
4 changes: 2 additions & 2 deletions src/PreRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public static function default(): PreRelease
/**
* @param string $preReleaseString the pre-release string
*
* @throws SemverException when the given pre-release string is invalid
*
* @return PreRelease the parsed pre-release part
*
* @throws SemverException when the given pre-release string is invalid
*/
public static function parse(string $preReleaseString): PreRelease
{
Expand Down
4 changes: 1 addition & 3 deletions src/SemverException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
/**
* Version and Constraint parsing throws this exception when the parsing fails due to an invalid format.
*/
class SemverException extends Exception
{
}
class SemverException extends Exception {}
28 changes: 14 additions & 14 deletions src/Traits/Comparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public function isNotEqual(Version $v): bool
* @param string $v1 the left side of the comparison
* @param string $v2 the right side of the comparison
*
* @throws SemverException when the version strings are invalid
*
* @return bool true when $v1 &lt; $v2, otherwise false
*
* @throws SemverException when the version strings are invalid
*/
public static function lessThan(string $v1, string $v2): bool
{
Expand All @@ -111,9 +111,9 @@ public static function lessThan(string $v1, string $v2): bool
* @param string $v1 the left side of the comparison
* @param string $v2 the right side of the comparison
*
* @throws SemverException when the version strings are invalid
*
* @return bool true when $v1 &lt;= $v2, otherwise false
*
* @throws SemverException when the version strings are invalid
*/
public static function lessThanOrEqual(string $v1, string $v2): bool
{
Expand All @@ -129,9 +129,9 @@ public static function lessThanOrEqual(string $v1, string $v2): bool
* @param string $v1 the left side of the comparison
* @param string $v2 the right side of the comparison
*
* @throws SemverException when the version strings are invalid
*
* @return bool true when $v1 &gt; $v2, otherwise false
*
* @throws SemverException when the version strings are invalid
*/
public static function greaterThan(string $v1, string $v2): bool
{
Expand All @@ -147,9 +147,9 @@ public static function greaterThan(string $v1, string $v2): bool
* @param string $v1 the left side of the comparison
* @param string $v2 the right side of the comparison
*
* @throws SemverException when the version strings are invalid
*
* @return bool true when $v1 &gt;= $v2, otherwise false
*
* @throws SemverException when the version strings are invalid
*/
public static function greaterThanOrEqual(string $v1, string $v2): bool
{
Expand All @@ -165,9 +165,9 @@ public static function greaterThanOrEqual(string $v1, string $v2): bool
* @param string $v1 the left side of the comparison
* @param string $v2 the right side of the comparison
*
* @throws SemverException when the version strings are invalid
*
* @return bool true when $v1 == $v2, otherwise false
*
* @throws SemverException when the version strings are invalid
*/
public static function equal(string $v1, string $v2): bool
{
Expand All @@ -183,9 +183,9 @@ public static function equal(string $v1, string $v2): bool
* @param string $v1 the left side of the comparison
* @param string $v2 the right side of the comparison
*
* @throws SemverException when the version strings are invalid
*
* @return bool true when $v1 != $v2, otherwise false
*
* @throws SemverException when the version strings are invalid
*/
public static function notEqual(string $v1, string $v2): bool
{
Expand All @@ -201,9 +201,9 @@ public static function notEqual(string $v1, string $v2): bool
* @param string $v1 the left side of the comparison
* @param string $v2 the right side of the comparison
*
* @throws SemverException when the version strings are invalid
*
* @return int -1 when $v1 < $v2, 0 when $v1 == $v2, 1 when $v1 > $v2
*
* @throws SemverException when the version strings are invalid
*/
public static function compareString(string $v1, string $v2): int
{
Expand Down
14 changes: 7 additions & 7 deletions src/Traits/Copyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ trait Copyable
* @param null|string $preRelease the pre-release part
* @param null|string $buildMeta the build metadata
*
* @throws SemverException when the version parts are invalid
*
* @return Version the new version
*
* @throws SemverException when the version parts are invalid
*/
public function copy(
int $major = null,
int $minor = null,
int $patch = null,
string $preRelease = null,
string $buildMeta = null
?int $major = null,
?int $minor = null,
?int $patch = null,
?string $preRelease = null,
?string $buildMeta = null
): Version {
return self::create(
null == $major ? $this->major : $major,
Expand Down
30 changes: 15 additions & 15 deletions src/Traits/NextProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ trait NextProducer
*
* @param null|string $preRelease the pre-release part
*
* @throws SemverException when the pre-release tag is non-null and invalid
*
* @return Version the next major version
*
* @throws SemverException when the pre-release tag is non-null and invalid
*/
public function getNextMajorVersion(string $preRelease = null): Version
public function getNextMajorVersion(?string $preRelease = null): Version
{
return new Version(
$this->major + 1,
Expand All @@ -38,11 +38,11 @@ public function getNextMajorVersion(string $preRelease = null): Version
*
* @param null|string $preRelease the pre-release part
*
* @throws SemverException when the pre-release tag is non-null and invalid
*
* @return Version the next minor version
*
* @throws SemverException when the pre-release tag is non-null and invalid
*/
public function getNextMinorVersion(string $preRelease = null): Version
public function getNextMinorVersion(?string $preRelease = null): Version
{
return new Version(
$this->major,
Expand All @@ -57,11 +57,11 @@ public function getNextMinorVersion(string $preRelease = null): Version
*
* @param null|string $preRelease the pre-release part
*
* @throws SemverException when the pre-release tag is non-null and invalid
*
* @return Version the next patch version
*
* @throws SemverException when the pre-release tag is non-null and invalid
*/
public function getNextPatchVersion(string $preRelease = null): Version
public function getNextPatchVersion(?string $preRelease = null): Version
{
return new Version(
$this->major,
Expand All @@ -76,11 +76,11 @@ public function getNextPatchVersion(string $preRelease = null): Version
*
* @param null|string $preRelease the pre-release part
*
* @throws SemverException when the pre-release tag is non-null and invalid
*
* @return Version the next pre-release version
*
* @throws SemverException when the pre-release tag is non-null and invalid
*/
public function getNextPreReleaseVersion(string $preRelease = null): Version
public function getNextPreReleaseVersion(?string $preRelease = null): Version
{
$pre = PreRelease::default();
if (!empty($preRelease)) {
Expand All @@ -106,11 +106,11 @@ public function getNextPreReleaseVersion(string $preRelease = null): Version
* @param int $by determines by which part the Version should be incremented
* @param null|string $preRelease the optional pre-release part
*
* @throws SemverException when the pre-release tag is non-null and invalid
*
* @return Version the incremented version
*
* @throws SemverException when the pre-release tag is non-null and invalid
*/
public function inc(int $by, string $preRelease = null): Version
public function inc(int $by, ?string $preRelease = null): Version
{
switch ($by) {
case Inc::MAJOR:
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public static function rsort(array $versions): array
*
* @param string[] $versions the version strings to sort
*
* @throws SemverException when the given array contains an invalid version string
*
* @return string[] the sorted array of version strings
*
* @throws SemverException when the given array contains an invalid version string
*/
public static function sortString(array $versions): array
{
Expand All @@ -79,9 +79,9 @@ public static function sortString(array $versions): array
*
* @param string[] $versions the version strings to sort
*
* @throws SemverException when the given array contains an invalid version string
*
* @return string[] the sorted array of version strings
*
* @throws SemverException when the given array contains an invalid version string
*/
public static function rsortString(array $versions): array
{
Expand Down
26 changes: 13 additions & 13 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class Version
/**
* Constructs a semantic version.
*
* @param $major int The major version number
* @param $minor int The minor version number
* @param $patch int The patch version number
* @param $major int The major version number
* @param $minor int The minor version number
* @param $patch int The patch version number
* @param null|PreRelease $preRelease the pre-release part
* @param null|string $buildMeta the build metadata
*/
private function __construct(
int $major,
int $minor,
int $patch,
PreRelease $preRelease = null,
string $buildMeta = null
?PreRelease $preRelease = null,
?string $buildMeta = null
) {
$this->major = $major;
$this->minor = $minor;
Expand Down Expand Up @@ -201,9 +201,9 @@ public static function parseOrNull(string $versionString, bool $strict = true):
* @param string $versionString the version string
* @param bool $strict enables or disables strict parsing
*
* @throws SemverException when the given version string is invalid
*
* @return Version the parsed version
*
* @throws SemverException when the given version string is invalid
*/
public static function parse(string $versionString, bool $strict = true): Version
{
Expand Down Expand Up @@ -261,16 +261,16 @@ public static function parse(string $versionString, bool $strict = true): Versio
* @param null|string $preRelease the pre-release part
* @param null|string $buildMeta the build metadata
*
* @throws SemverException when the version parts are invalid
*
* @return Version the new version
*
* @throws SemverException when the version parts are invalid
*/
public static function create(
int $major,
int $minor,
int $patch,
string $preRelease = null,
string $buildMeta = null
?string $preRelease = null,
?string $buildMeta = null
): Version {
self::ensure($major >= 0, 'The major number must be >= 0.');
self::ensure($minor >= 0, 'The minor number must be >= 0.');
Expand All @@ -291,9 +291,9 @@ public static function create(
* @param string $versionString the version to check
* @param string $constraintString the constraint to satisfy
*
* @throws SemverException when the version string or the constraint string is invalid
*
* @return bool true when the given version satisfies the given constraint, otherwise false
*
* @throws SemverException when the version string or the constraint string is invalid
*/
public static function satisfies(string $versionString, string $constraintString): bool
{
Expand Down
8 changes: 4 additions & 4 deletions tests/ConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testRanges()
$this->assertEquals('<=1.0.0', (new Range($start, $end, Op::GREATER_THAN_OR_EQUAL))->opposite());
}

public function dataInvalid(): array
public static function dataInvalid(): array
{
return [
['a'],
Expand All @@ -89,7 +89,7 @@ public function dataInvalid(): array
];
}

public function dataSatisfies(): array
public static function dataSatisfies(): array
{
return [
["<\t1.0.0", '0.1.2'],
Expand Down Expand Up @@ -263,7 +263,7 @@ public function dataSatisfies(): array
];
}

public function dataNotSatisfies(): array
public static function dataNotSatisfies(): array
{
return [
['~1.2.3-alpha.2', '1.3.4-alpha.2'],
Expand Down Expand Up @@ -443,7 +443,7 @@ public function dataNotSatisfies(): array
];
}

public function dataParse(): array
public static function dataParse(): array
{
return [
['1.2.3 - 2.3.4', '>=1.2.3 <=2.3.4'],
Expand Down
2 changes: 1 addition & 1 deletion tests/NextVersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testInc(string $source, int $incBy, string $expected, ?string $p
$this->assertEquals($expected, (string) Version::parse($source)->inc($incBy, $preRelease));
}

public function data(): array
public static function data(): array
{
return [
['1.2.3', Inc::MAJOR, '2.0.0', null],
Expand Down
Loading

0 comments on commit 2050543

Please sign in to comment.