Skip to content

Commit 9b4b5ec

Browse files
committed
chore: updated Config validation and removed old validator
1 parent 6202638 commit 9b4b5ec

14 files changed

+6
-315
lines changed

src/Config.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap;
44

5-
use ProgrammatorDev\OpenWeatherMap\Exception\ValidationException;
65
use ProgrammatorDev\OpenWeatherMap\HttpClient\HttpClientBuilder;
76
use ProgrammatorDev\OpenWeatherMap\Language\Language;
87
use ProgrammatorDev\OpenWeatherMap\UnitSystem\UnitSystem;
9-
use ProgrammatorDev\OpenWeatherMap\Validator\BlankValidatorTrait;
10-
use ProgrammatorDev\OpenWeatherMap\Validator\ChoiceValidatorTrait;
8+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
9+
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1110
use Psr\Cache\CacheItemPoolInterface;
1211
use Psr\Log\LoggerInterface;
1312
use Symfony\Component\OptionsResolver\OptionsResolver;
1413

1514
class Config
1615
{
17-
use BlankValidatorTrait;
18-
use ChoiceValidatorTrait;
19-
2016
private array $options;
2117

2218
public function __construct(array $options = [])
@@ -62,7 +58,7 @@ public function getApplicationKey(): string
6258
*/
6359
public function setApplicationKey(string $applicationKey): self
6460
{
65-
$this->validateBlank('applicationKey', $applicationKey);
61+
Validator::notBlank()->assert($applicationKey, 'applicationKey');
6662

6763
$this->options['applicationKey'] = $applicationKey;
6864

@@ -79,7 +75,7 @@ public function getUnitSystem(): string
7975
*/
8076
public function setUnitSystem(string $unitSystem): self
8177
{
82-
$this->validateChoice('unitSystem', $unitSystem, UnitSystem::getList());
78+
Validator::choice(UnitSystem::getList())->assert($unitSystem, 'unitSystem');
8379

8480
$this->options['unitSystem'] = $unitSystem;
8581

@@ -96,7 +92,7 @@ public function getLanguage(): string
9692
*/
9793
public function setLanguage(string $language): self
9894
{
99-
$this->validateChoice('language', $language, Language::getList());
95+
Validator::choice(Language::getList())->assert($language, 'language');
10096

10197
$this->options['language'] = $language;
10298

src/Endpoint/OneCallEndpoint.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313
use ProgrammatorDev\OpenWeatherMap\Exception\TooManyRequestsException;
1414
use ProgrammatorDev\OpenWeatherMap\Exception\UnauthorizedException;
1515
use ProgrammatorDev\OpenWeatherMap\Exception\UnexpectedErrorException;
16-
use ProgrammatorDev\OpenWeatherMap\Validator\CoordinateValidatorTrait;
17-
use ProgrammatorDev\OpenWeatherMap\Validator\LessThanValidatorTrait;
1816
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
1917
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
2018

2119
class OneCallEndpoint extends AbstractEndpoint
2220
{
2321
use WithUnitSystemTrait;
2422
use WithLanguageTrait;
25-
use CoordinateValidatorTrait;
26-
use LessThanValidatorTrait;
2723

2824
private string $urlOneCall = 'https://api.openweathermap.org/data/3.0/onecall';
2925

src/Endpoint/Util/WithLanguageTrait.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
namespace ProgrammatorDev\OpenWeatherMap\Endpoint\Util;
44

55
use ProgrammatorDev\OpenWeatherMap\Language\Language;
6-
use ProgrammatorDev\OpenWeatherMap\Validator\ChoiceValidatorTrait;
76
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
87
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
98

109
trait WithLanguageTrait
1110
{
12-
use ChoiceValidatorTrait;
13-
1411
/**
1512
* @throws ValidationException
1613
*/

src/Endpoint/Util/WithUnitSystemTrait.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
namespace ProgrammatorDev\OpenWeatherMap\Endpoint\Util;
44

55
use ProgrammatorDev\OpenWeatherMap\UnitSystem\UnitSystem;
6-
use ProgrammatorDev\OpenWeatherMap\Validator\ChoiceValidatorTrait;
76
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
87
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
98

109
trait WithUnitSystemTrait
1110
{
12-
use ChoiceValidatorTrait;
13-
1411
/**
1512
* @throws ValidationException
1613
*/

src/Endpoint/WeatherEndpoint.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
use ProgrammatorDev\OpenWeatherMap\Exception\TooManyRequestsException;
1313
use ProgrammatorDev\OpenWeatherMap\Exception\UnauthorizedException;
1414
use ProgrammatorDev\OpenWeatherMap\Exception\UnexpectedErrorException;
15-
use ProgrammatorDev\OpenWeatherMap\Validator\CoordinateValidatorTrait;
16-
use ProgrammatorDev\OpenWeatherMap\Validator\GreaterThanValidatorTrait;
1715
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
1816
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1917

2018
class WeatherEndpoint extends AbstractEndpoint
2119
{
2220
use WithUnitSystemTrait;
2321
use WithLanguageTrait;
24-
use CoordinateValidatorTrait;
25-
use GreaterThanValidatorTrait;
2622

2723
private const NUM_RESULTS = 40;
2824

src/Exception/ValidationException.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/Validator/BetweenValidatorTrait.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/Validator/BlankValidatorTrait.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Validator/ChoiceValidatorTrait.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Validator/CoordinateValidatorTrait.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)