Skip to content

Commit 9148075

Browse files
authored
Merge pull request #11 from factorio-item-browser/feature/combination-validation
feature/combination-validation
2 parents 3a67a97 + 951a386 commit 9148075

File tree

14 files changed

+646
-0
lines changed

14 files changed

+646
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.2.0 - 2020-11-01
4+
5+
### Added
6+
7+
- New `/combination/validate` request.
8+
39
## 3.1.0 - 2020-05-02
410

511
### Added

config/dependencies.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Endpoint\Auth\AuthEndpoint::class => InvokableFactory::class,
2525
Endpoint\Combination\CombinationExportEndpoint::class => InvokableFactory::class,
2626
Endpoint\Combination\CombinationStatusEndpoint::class => InvokableFactory::class,
27+
Endpoint\Combination\CombinationValidateEndpoint::class => InvokableFactory::class,
2728
Endpoint\Generic\GenericDetailsEndpoint::class => InvokableFactory::class,
2829
Endpoint\Generic\GenericIconEndpoint::class => InvokableFactory::class,
2930
Endpoint\Item\ItemIngredientEndpoint::class => InvokableFactory::class,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FactorioItemBrowser\Api\Client\Entity\ValidatedMod:
2+
access_type: public_method
3+
exclusion_policy: all
4+
properties:
5+
name:
6+
type: string
7+
version:
8+
type: string
9+
issueType:
10+
type: string
11+
issueDependency:
12+
type: string
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FactorioItemBrowser\Api\Client\Response\Combination\CombinationValidateResponse:
2+
access_type: public_method
3+
exclusion_policy: all
4+
properties:
5+
isValid:
6+
type: bool
7+
validatedMods:
8+
type: array<FactorioItemBrowser\Api\Client\Entity\ValidatedMod>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace FactorioItemBrowser\Api\Client\Constant;
6+
7+
/**
8+
* The issue types of the validated mods.
9+
*
10+
* @author BluePsyduck <[email protected]>
11+
* @license http://opensource.org/licenses/GPL-3.0 GPL v3
12+
*/
13+
interface ValidatedModIssueType
14+
{
15+
/**
16+
* The mod is in conflict with another mod.
17+
*/
18+
public const CONFLICT = 'conflict';
19+
20+
/**
21+
* The mod is missing a mandatory dependency.
22+
*/
23+
public const MISSING_DEPENDENCY = 'missing-dependency';
24+
25+
/**
26+
* The mod is missing on the mod portal.
27+
*/
28+
public const MISSING_MOD = 'missing-mod';
29+
30+
/**
31+
* The mod is missing a valid release which can be used.
32+
*/
33+
public const MISSING_RELEASE = 'missing-release';
34+
35+
/**
36+
* The mod does not have any issues.
37+
*/
38+
public const NONE = 'none';
39+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace FactorioItemBrowser\Api\Client\Endpoint\Combination;
6+
7+
use FactorioItemBrowser\Api\Client\Endpoint\EndpointInterface;
8+
use FactorioItemBrowser\Api\Client\Request\Combination\CombinationValidateRequest;
9+
use FactorioItemBrowser\Api\Client\Response\Combination\CombinationValidateResponse;
10+
11+
/**
12+
* The endpoint for the combination validate request.
13+
*
14+
* @author BluePsyduck <[email protected]>
15+
* @license http://opensource.org/licenses/GPL-3.0 GPL v3
16+
*/
17+
class CombinationValidateEndpoint implements EndpointInterface
18+
{
19+
/**
20+
* Returns the request class supported by the endpoint.
21+
* @return string
22+
*/
23+
public function getSupportedRequestClass(): string
24+
{
25+
return CombinationValidateRequest::class;
26+
}
27+
28+
/**
29+
* Returns whether or not this endpoint requires an authorization token.
30+
* @return bool
31+
*/
32+
public function requiresAuthorizationToken(): bool
33+
{
34+
return true;
35+
}
36+
37+
/**
38+
* Returns the request path of the endpoint.
39+
* @return string
40+
*/
41+
public function getRequestPath(): string
42+
{
43+
return 'combination/validate';
44+
}
45+
46+
/**
47+
* Creates the response of the endpoint.
48+
* @return string
49+
*/
50+
public function getResponseClass(): string
51+
{
52+
return CombinationValidateResponse::class;
53+
}
54+
}

src/Entity/ValidatedMod.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace FactorioItemBrowser\Api\Client\Entity;
6+
7+
use FactorioItemBrowser\Api\Client\Constant\ValidatedModIssueType;
8+
9+
/**
10+
* The entity representing a validated mod.
11+
*
12+
* @author BluePsyduck <[email protected]>
13+
* @license http://opensource.org/licenses/GPL-3.0 GPL v3
14+
*/
15+
class ValidatedMod
16+
{
17+
/**
18+
* The name of the mod.
19+
* @var string
20+
*/
21+
protected $name = '';
22+
23+
/**
24+
* The version of the mod used for validation.
25+
* @var string
26+
*/
27+
protected $version = '';
28+
29+
/**
30+
* The type of issue the mod has.
31+
* @var string
32+
*/
33+
protected $issueType = ValidatedModIssueType::NONE;
34+
35+
/**
36+
* The dependency which triggered the "missing-dependency" or "conflict" issue.
37+
* @var string
38+
*/
39+
protected $issueDependency = '';
40+
41+
/**
42+
* Sets the name of the mod.
43+
* @param string $name
44+
* @return $this
45+
*/
46+
public function setName(string $name): self
47+
{
48+
$this->name = $name;
49+
return $this;
50+
}
51+
52+
/**
53+
* Returns the name of the mod.
54+
* @return string
55+
*/
56+
public function getName(): string
57+
{
58+
return $this->name;
59+
}
60+
61+
/**
62+
* Sets the version of the mod used for validation.
63+
* @param string $version
64+
* @return $this
65+
*/
66+
public function setVersion(string $version): self
67+
{
68+
$this->version = $version;
69+
return $this;
70+
}
71+
72+
/**
73+
* Returns the version of the mod used for validation.
74+
* @return string
75+
*/
76+
public function getVersion(): string
77+
{
78+
return $this->version;
79+
}
80+
81+
/**
82+
* Sets the type of issue the mod has.
83+
* @param string $issueType
84+
* @return $this
85+
*/
86+
public function setIssueType(string $issueType): self
87+
{
88+
$this->issueType = $issueType;
89+
return $this;
90+
}
91+
92+
/**
93+
* Returns the type of issue the mod has.
94+
* @return string
95+
*/
96+
public function getIssueType(): string
97+
{
98+
return $this->issueType;
99+
}
100+
101+
/**
102+
* Sets the dependency which triggered the "missing-dependency" or "conflict" issue.
103+
* @param string $issueDependency
104+
* @return $this
105+
*/
106+
public function setIssueDependency(string $issueDependency): self
107+
{
108+
$this->issueDependency = $issueDependency;
109+
return $this;
110+
}
111+
112+
/**
113+
* Returns the dependency which triggered the "missing-dependency" or "conflict" issue.
114+
* @return string
115+
*/
116+
public function getIssueDependency(): string
117+
{
118+
return $this->issueDependency;
119+
}
120+
}
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 FactorioItemBrowser\Api\Client\Request\Combination;
6+
7+
use FactorioItemBrowser\Api\Client\Request\RequestInterface;
8+
9+
/**
10+
* The request of the combination validation.
11+
*
12+
* @author BluePsyduck <[email protected]>
13+
* @license http://opensource.org/licenses/GPL-3.0 GPL v3
14+
*/
15+
class CombinationValidateRequest implements RequestInterface
16+
{
17+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace FactorioItemBrowser\Api\Client\Response\Combination;
6+
7+
use FactorioItemBrowser\Api\Client\Entity\ValidatedMod;
8+
use FactorioItemBrowser\Api\Client\Response\ResponseInterface;
9+
10+
/**
11+
* The response of the combination validate request.
12+
*
13+
* @author BluePsyduck <[email protected]>
14+
* @license http://opensource.org/licenses/GPL-3.0 GPL v3
15+
*/
16+
class CombinationValidateResponse implements ResponseInterface
17+
{
18+
/**
19+
* Whether the combination of mods is valid.
20+
* @var bool
21+
*/
22+
protected $isValid = false;
23+
24+
/**
25+
* The list of validated mods.
26+
* @var array<ValidatedMod>|ValidatedMod[]
27+
*/
28+
protected $validatedMods = [];
29+
30+
/**
31+
* Sets whether the combination of mods is valid.
32+
* @param bool $isValid
33+
* @return $this
34+
*/
35+
public function setIsValid(bool $isValid): self
36+
{
37+
$this->isValid = $isValid;
38+
return $this;
39+
}
40+
41+
/**
42+
* Returns whether the combination of mods is valid.
43+
* @return bool
44+
*/
45+
public function getIsValid(): bool
46+
{
47+
return $this->isValid;
48+
}
49+
50+
/**
51+
* Sets the list of validated mods.
52+
* @param array|ValidatedMod[] $validatedMods
53+
* @return $this
54+
*/
55+
public function setValidatedMods(array $validatedMods): self
56+
{
57+
$this->validatedMods = $validatedMods;
58+
return $this;
59+
}
60+
61+
/**
62+
* Adds a validated mod to the list.
63+
* @param ValidatedMod $validatedMod
64+
* @return $this
65+
*/
66+
public function addValidatedMod(ValidatedMod $validatedMod): self
67+
{
68+
$this->validatedMods[] = $validatedMod;
69+
return $this;
70+
}
71+
72+
/**
73+
* Returns the list of validated mods.
74+
* @return array|ValidatedMod[]
75+
*/
76+
public function getValidatedMods(): array
77+
{
78+
return $this->validatedMods;
79+
}
80+
}

0 commit comments

Comments
 (0)