Skip to content

Commit 6202638

Browse files
committed
chore: updated endpoint traits validation
1 parent 9ed3b8a commit 6202638

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Endpoint/Util/WithLanguageTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55
use ProgrammatorDev\OpenWeatherMap\Language\Language;
66
use ProgrammatorDev\OpenWeatherMap\Validator\ChoiceValidatorTrait;
7+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
8+
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
79

810
trait WithLanguageTrait
911
{
1012
use ChoiceValidatorTrait;
1113

14+
/**
15+
* @throws ValidationException
16+
*/
1217
public function withLanguage(string $language): static
1318
{
14-
$this->validateChoice('language', $language, Language::getList());
19+
Validator::choice(Language::getList())->assert($language, 'language');
1520

1621
$clone = clone $this;
1722
$clone->language = $language;

src/Endpoint/Util/WithUnitSystemTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55
use ProgrammatorDev\OpenWeatherMap\UnitSystem\UnitSystem;
66
use ProgrammatorDev\OpenWeatherMap\Validator\ChoiceValidatorTrait;
7+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
8+
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
79

810
trait WithUnitSystemTrait
911
{
1012
use ChoiceValidatorTrait;
1113

14+
/**
15+
* @throws ValidationException
16+
*/
1217
public function withUnitSystem(string $unitSystem): static
1318
{
14-
$this->validateChoice('unitSystem', $unitSystem, UnitSystem::getList());
19+
Validator::choice(UnitSystem::getList())->assert($unitSystem, 'unitSystem');
1520

1621
$clone = clone $this;
1722
$clone->unitSystem = $unitSystem;

0 commit comments

Comments
 (0)