Skip to content

Commit 1060235

Browse files
committed
Add VersionChecker implementation, add interfaces
1 parent cfb3aef commit 1060235

13 files changed

Lines changed: 494 additions & 3 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
.php_cs
33
.php_cs.cache
4+
.phpunit.cache
45
.phpunit.result.cache
56
build
67
composer.lock

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="4"
3+
errorLevel="1"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xmlns="https://getpsalm.org/schema/config"
66
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Exception;
6+
7+
final class RoadrunnerNotInstalledException extends VersionCheckerException
8+
{
9+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Exception;
6+
7+
final class UnsupportedVersionException extends VersionCheckerException
8+
{
9+
/**
10+
* @param non-empty-string $message
11+
* @param non-empty-string $installed
12+
* @param non-empty-string $requested
13+
*/
14+
public function __construct(
15+
string $message,
16+
private readonly string $installed,
17+
private readonly string $requested
18+
) {
19+
parent::__construct($message);
20+
}
21+
22+
/**
23+
* @return non-empty-string
24+
*/
25+
public function getInstalledVersion(): string
26+
{
27+
return $this->installed;
28+
}
29+
30+
/**
31+
* @return non-empty-string
32+
*/
33+
public function getRequestedVersion(): string
34+
{
35+
return $this->requested;
36+
}
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Exception;
6+
7+
abstract class VersionCheckerException extends \Exception
8+
{
9+
}

src/Version/Comparator.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Version;
6+
7+
final class Comparator implements ComparatorInterface
8+
{
9+
/**
10+
* @param non-empty-string $requested
11+
* @param non-empty-string $installed
12+
*/
13+
public function greaterThan(string $requested, string $installed): bool
14+
{
15+
// TODO need implementation
16+
17+
return true;
18+
}
19+
20+
/**
21+
* @param non-empty-string $requested
22+
* @param non-empty-string $installed
23+
*/
24+
public function lessThan(string $requested, string $installed): bool
25+
{
26+
// TODO need implementation
27+
28+
return true;
29+
}
30+
31+
/**
32+
* @param non-empty-string $requested
33+
* @param non-empty-string $installed
34+
*/
35+
public function equal(string $requested, string $installed): bool
36+
{
37+
// TODO need implementation
38+
39+
return true;
40+
}
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Version;
6+
7+
interface ComparatorInterface
8+
{
9+
/**
10+
* @param non-empty-string $requested
11+
* @param non-empty-string $installed
12+
*/
13+
public function greaterThan(string $requested, string $installed): bool;
14+
15+
/**
16+
* @param non-empty-string $requested
17+
* @param non-empty-string $installed
18+
*/
19+
public function lessThan(string $requested, string $installed): bool;
20+
21+
/**
22+
* @param non-empty-string $requested
23+
* @param non-empty-string $installed
24+
*/
25+
public function equal(string $requested, string $installed): bool;
26+
}

src/Version/Installed.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Version;
6+
7+
use RoadRunner\VersionChecker\Exception\RoadrunnerNotInstalledException;
8+
9+
final class Installed implements InstalledInterface
10+
{
11+
/**
12+
* @return non-empty-string
13+
*
14+
* @throws RoadrunnerNotInstalledException
15+
*/
16+
public function getInstalledVersion(): string
17+
{
18+
// TODO need implementation
19+
20+
throw new RoadrunnerNotInstalledException();
21+
}
22+
}

src/Version/InstalledInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Version;
6+
7+
use RoadRunner\VersionChecker\Exception\RoadrunnerNotInstalledException;
8+
9+
interface InstalledInterface
10+
{
11+
/**
12+
* @return non-empty-string
13+
*
14+
* @throws RoadrunnerNotInstalledException
15+
*/
16+
public function getInstalledVersion(): string;
17+
}

src/Version/Required.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RoadRunner\VersionChecker\Version;
6+
7+
final class Required implements RequiredInterface
8+
{
9+
/**
10+
* @return non-empty-string
11+
*/
12+
public function getRequiredVersion(): string
13+
{
14+
return '1.0'; // TODO need implementation
15+
}
16+
}

0 commit comments

Comments
 (0)