Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Explicitly mark parameters as nullable #42

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ parameters:
paths:
- src
- tests
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
earlyTerminatingMethodCalls:
Version\Comparison\Constraint\OperationConstraintParser:
- error
ignoreErrors:
- '~Method [a-zA-Z0-9\\_]+::matches\(\) has parameter \$[a-zA-Z0-9]+ with no type specified.~'
- identifier: missingType.generics
- identifier: missingType.iterableValue


includes:
Expand Down
15 changes: 7 additions & 8 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Version implements JsonSerializable

protected static ?Comparator $comparator = null;

final protected function __construct(int $major, int $minor, int $patch, PreRelease $preRelease = null, Build $build = null)
final protected function __construct(int $major, int $minor, int $patch, ?PreRelease $preRelease = null, ?Build $build = null)
{
VersionAssert::that($major)->greaterOrEqualThan(0, 'Major version must be positive integer');
VersionAssert::that($minor)->greaterOrEqualThan(0, 'Minor version must be positive integer');
Expand All @@ -44,7 +44,7 @@ final protected function __construct(int $major, int $minor, int $patch, PreRele
$this->build = $build;
}

public static function from(int $major, int $minor = 0, int $patch = 0, PreRelease $preRelease = null, Build $build = null): Version
public static function from(int $major, int $minor = 0, int $patch = 0, ?PreRelease $preRelease = null, ?Build $build = null): Version
{
return new static($major, $minor, $patch, $preRelease, $build);
}
Expand All @@ -59,13 +59,13 @@ public static function fromString(string $versionString): Version
}

$version = new static(
(int) $parts['major'],
(int) $parts['minor'],
(int) $parts['patch'],
(int)$parts['major'],
(int)$parts['minor'],
(int)$parts['patch'],
(isset($parts['preRelease']) && '' !== $parts['preRelease']) ? PreRelease::fromString($parts['preRelease']) : null,
(isset($parts['build']) && '' !== $parts['build']) ? Build::fromString($parts['build']) : null
);
$version->prefix = $parts['prefix'] ?? '';
$version->prefix = $parts['prefix'];

return $version;
}
Expand Down Expand Up @@ -208,8 +208,7 @@ public function toString(): string
. '.' . $this->minor
. '.' . $this->patch
. (($this->preRelease !== null) ? '-' . $this->preRelease->toString() : '')
. (($this->build !== null) ? '+' . $this->build->toString() : '')
;
. (($this->build !== null) ? '+' . $this->build->toString() : '');
}

public function __toString(): string
Expand Down
10 changes: 5 additions & 5 deletions tests/TestAsset/VersionIsIdentical.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ final class VersionIsIdentical extends Constraint
private Version $expectedVersion;

public function __construct(
int $expectedMajor,
int $expectedMinor,
int $expectedPatch,
PreRelease|string $expectedPreRelease = null,
Build|string $expectedBuild = null
int $expectedMajor,
int $expectedMinor,
int $expectedPatch,
PreRelease|string|null $expectedPreRelease = null,
Build|string|null $expectedBuild = null
) {
$this->expectedVersion = Version::from(
$expectedMajor,
Expand Down