diff --git a/src/AbstractVersion.php b/src/AbstractVersion.php index eae0bc1..368a65e 100644 --- a/src/AbstractVersion.php +++ b/src/AbstractVersion.php @@ -20,8 +20,7 @@ abstract class AbstractVersion implements IVersion * which is a value of any type other than a resource. * @since 5.4.0 */ - #[\ReturnTypeWillChange] - public function jsonSerialize() + public function jsonSerialize(): mixed { return [ 'branch' => $this->getBranch(), @@ -42,11 +41,11 @@ public function exists(): bool * Get the branch string. * @return string|null */ - abstract public function getBranch(); + abstract public function getBranch(): ?string; /** * Get the latest commit ID. * @return string|null */ - abstract public function getCommit(); + abstract public function getCommit(): ?string; } diff --git a/src/FileVersion.php b/src/FileVersion.php index 54f8d7e..63963f6 100644 --- a/src/FileVersion.php +++ b/src/FileVersion.php @@ -33,7 +33,7 @@ class FileVersion extends AbstractVersion * deployment script. * @param string $file The JSON formatted file containig branch and commit. */ - public function __construct($file) + public function __construct(string $file) { $this->file = $file; } @@ -83,7 +83,7 @@ private function fileContents(): array * Get the branch string. * @return string|null */ - public function getBranch() + public function getBranch(): ?string { if ($this->fileContents === null) { $this->fileContents = $this->fileContents(); @@ -95,7 +95,7 @@ public function getBranch() * Get the latest commit ID. * @return string|null */ - public function getCommit() + public function getCommit(): ?string { if ($this->fileContents === null) { $this->fileContents = $this->fileContents(); diff --git a/src/GitVersion.php b/src/GitVersion.php index 87c5ade..4a864f3 100644 --- a/src/GitVersion.php +++ b/src/GitVersion.php @@ -42,10 +42,10 @@ class GitVersion extends AbstractVersion * GitVersion constructor. * @param string $appDir The application directory. */ - public function __construct($appDir) + public function __construct(string $appDir) { - $this->dir = $appDir.DIRECTORY_SEPARATOR.'.git'; - $this->head = $this->dir.DIRECTORY_SEPARATOR.'HEAD'; + $this->dir = $appDir . DIRECTORY_SEPARATOR . '.git'; + $this->head = $this->dir . DIRECTORY_SEPARATOR . 'HEAD'; } /** @@ -64,7 +64,7 @@ private function isRepo(): bool * Get the branch string. * @return string|null */ - public function getBranch() + public function getBranch(): ?string { if ($this->branch === null && $this->isRepo()) { $lines = file($this->head); @@ -81,16 +81,16 @@ public function getBranch() * Get the latest commit ID. * @return string */ - public function getCommit() + public function getCommit(): string { if ($this->commit === null && $this->isRepo()) { /** * Build filepath from branch name. */ - $refFile = $this->dir.DIRECTORY_SEPARATOR - .'refs'.DIRECTORY_SEPARATOR - .'heads'.DIRECTORY_SEPARATOR - .$this->getBranch(); + $refFile = $this->dir . DIRECTORY_SEPARATOR + . 'refs' . DIRECTORY_SEPARATOR + . 'heads' . DIRECTORY_SEPARATOR + . $this->getBranch(); /** * read ref file */ diff --git a/src/IVersion.php b/src/IVersion.php index 0ce87a3..6147c19 100644 --- a/src/IVersion.php +++ b/src/IVersion.php @@ -20,13 +20,13 @@ public function exists(): bool; /** * Get the branch string. - * @return string + * @return string|null */ - public function getBranch(); + public function getBranch(): ?string; /** * Get the latest commit ID. - * @return string + * @return string|null */ - public function getCommit(); + public function getCommit(): ?string; } diff --git a/src/Version.php b/src/Version.php index a482f4e..050e7aa 100644 --- a/src/Version.php +++ b/src/Version.php @@ -36,7 +36,7 @@ public function __construct() * @param \kbATeam\Version\IVersion $version * @return void */ - public function register(IVersion $version) + public function register(IVersion $version): void { $this->versions[] = $version; } @@ -68,7 +68,7 @@ private function determineVersion(): array * Get the branch string. * @return string|null */ - public function getBranch() + public function getBranch(): ?string { if ($this->version === null) { $this->version = $this->determineVersion(); @@ -80,7 +80,7 @@ public function getBranch() * Get the latest commit ID. * @return string|null */ - public function getCommit() + public function getCommit(): ?string { if ($this->version === null) { $this->version = $this->determineVersion(); diff --git a/tests/FileVersionTest.php b/tests/FileVersionTest.php index cb562ea..e3f59af 100644 --- a/tests/FileVersionTest.php +++ b/tests/FileVersionTest.php @@ -54,7 +54,7 @@ protected function tearDown(): void * Test retrieving branch and commit from a JSON encoded file. * @return void */ - public function testFileVersionRetrieval() + public function testFileVersionRetrieval(): void { $fileVersion = new FileVersion($this->tempDir.'/commit.json'); $this->assertInstanceOf(IVersion::class, $fileVersion); @@ -73,7 +73,7 @@ public function testFileVersionRetrieval() * Test retrieving commit from a JSON encoded file. * @return void */ - public function testGettingCommit() + public function testGettingCommit(): void { $fileVersion = new FileVersion($this->tempDir.'/commit.json'); $this->assertSame('9c9e437', $fileVersion->getCommit()); @@ -83,7 +83,7 @@ public function testGettingCommit() * Test retrieving branch from a JSON encoded file. * @return void */ - public function testGettingBranch() + public function testGettingBranch(): void { $fileVersion = new FileVersion($this->tempDir.'/commit.json'); $this->assertSame('master', $fileVersion->getBranch()); diff --git a/tests/GitVersionTest.php b/tests/GitVersionTest.php index 4b6a1dd..7ab4a96 100644 --- a/tests/GitVersionTest.php +++ b/tests/GitVersionTest.php @@ -53,7 +53,7 @@ protected function tearDown(): void * Test retrieving version information from git. * @return void */ - public function testGitVersionRetrieval() + public function testGitVersionRetrieval(): void { $gitVersion = new GitVersion($this->tempDir); $this->assertInstanceOf(IVersion::class, $gitVersion); diff --git a/tests/TempDirTrait.php b/tests/TempDirTrait.php index bb64bf8..5958f22 100644 --- a/tests/TempDirTrait.php +++ b/tests/TempDirTrait.php @@ -18,7 +18,7 @@ trait TempDirTrait * @return string * @throws \RuntimeException */ - private static function tempdir() + private static function tempdir(): string { ob_start(); $result = system('mktemp -d', $exitCode); @@ -38,7 +38,7 @@ private static function tempdir() * @throws \RuntimeException * @return void */ - private static function rmDir($dir) + private static function rmDir(string $dir): void { if (!is_dir($dir)) { throw new \RuntimeException(sprintf("Directory %s doesn't exist", $dir)); diff --git a/tests/VersionTest.php b/tests/VersionTest.php index 1d96f4f..ca23e78 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -60,7 +60,7 @@ protected function tearDown(): void * git repository. * @return void */ - public function testRetrievingFileVersion() + public function testRetrievingFileVersion(): void { $version = new Version(); $this->assertInstanceOf(IVersion::class, $version); @@ -83,7 +83,7 @@ public function testRetrievingFileVersion() * encoded file. * @return void */ - public function testRetrievingGitVersion() + public function testRetrievingGitVersion(): void { $version = new Version(); $this->assertInstanceOf(IVersion::class, $version);