@@ -30,9 +30,9 @@ use ProgrammatorDev\YetAnotherPhpValidator\Validator;
3030 */
3131function getWeatherTemperature(float $latitude, float $longitude, string $unitSystem): float
3232{
33- Validator::range(-90, 90)->assert($latitude, 'Latitude ');
34- Validator::range(-180, 180)->assert($longitude, 'Longitude ');
35- Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'Unit System ');
33+ Validator::range(-90, 90)->assert($latitude, 'latitude ');
34+ Validator::range(-180, 180)->assert($longitude, 'longitude ');
35+ Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'unit system ');
3636
3737 // ...
3838}
@@ -50,9 +50,9 @@ use ProgrammatorDev\YetAnotherPhpValidator\Validator;
5050 */
5151function getWeatherTemperature(float $latitude, float $longitude, string $unitSystem): float
5252{
53- (new Validator(new Rule\Range(-90, 90)))->assert($latitude, 'Latitude ');
54- (new Validator(new Rule\Range(-180, 180)))->assert($longitude, 'Longitude ');
55- (new Validator(new Rule\NotBlank(), new Rule\Choice(['METRIC', 'IMPERIAL'])))->assert($unitSystem, 'Unit System ');
53+ (new Validator(new Rule\Range(-90, 90)))->assert($latitude, 'latitude ');
54+ (new Validator(new Rule\Range(-180, 180)))->assert($longitude, 'longitude ');
55+ (new Validator(new Rule\NotBlank(), new Rule\Choice(['METRIC', 'IMPERIAL'])))->assert($unitSystem, 'unit system ');
5656
5757 // ...
5858}
@@ -68,7 +68,7 @@ This method throws a `ValidationException` when a rule fails, otherwise nothing
6868/**
6969 * @throws ValidationException
7070 */
71- assert(mixed $value, string $name): void;
71+ assert(mixed $value, ? string $name = null ): void;
7272```
7373
7474An example on how to handle an error:
@@ -79,9 +79,9 @@ use ProgrammatorDev\YetAnotherPhpValidator\Validator;
7979
8080function getWeatherTemperature(float $latitude, float $longitude, string $unitSystem): float
8181{
82- Validator::range(-90, 90)->assert($latitude, 'Latitude ');
83- Validator::range(-180, 180)->assert($longitude, 'Longitude ');
84- Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'Unit System ');
82+ Validator::range(-90, 90)->assert($latitude, 'latitude ');
83+ Validator::range(-180, 180)->assert($longitude, 'longitude ');
84+ Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'unit system ');
8585
8686 // ...
8787}
9090 getWeatherTemperature(latitude: 100, longitude: 50, unitSystem: 'METRIC');
9191}
9292catch (ValidationException $exception) {
93- echo $exception->getMessage(); // The "Latitude" value should be between " -90" and "90", " 100" given.
93+ echo $exception->getMessage(); // The latitude value should be between -90 and 90, 100 given.
9494}
9595```
9696> ** Note**
@@ -175,7 +175,7 @@ function calculateDiscount(float $price, float $discount, string $type): float
175175 $discountValidator->addRule(new Rule\LessThanOrEqual(100));
176176 }
177177
178- $discountValidator->assert($discount, 'Discount ');
178+ $discountValidator->assert($discount, 'discount ');
179179
180180 // ...
181181}
@@ -197,9 +197,9 @@ use ProgrammatorDev\YetAnotherPhpValidator\Exception;
197197use ProgrammatorDev\YetAnotherPhpValidator\Validator;
198198
199199try {
200- Validator::range(-90, 90)->assert($latitude, 'Latitude ');
201- Validator::range(-180, 180)->assert($longitude, 'Longitude ');
202- Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'Unit System ');
200+ Validator::range(-90, 90)->assert($latitude, 'latitude ');
201+ Validator::range(-180, 180)->assert($longitude, 'longitude ');
202+ Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'unit system ');
203203}
204204catch (Exception\RangeException $exception) {
205205 // Do something when Range fails
@@ -219,9 +219,9 @@ use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
219219use ProgrammatorDev\YetAnotherPhpValidator\Validator;
220220
221221try {
222- Validator::range(-90, 90)->assert($latitude, 'Latitude ');
223- Validator::range(-180, 180)->assert($longitude, 'Longitude ');
224- Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'Unit System ');
222+ Validator::range(-90, 90)->assert($latitude, 'latitude ');
223+ Validator::range(-180, 180)->assert($longitude, 'longitude ');
224+ Validator::notBlank()->choice(['METRIC', 'IMPERIAL'])->assert($unitSystem, 'unit system ');
225225}
226226catch (ValidationException $exception) {
227227 // Do something when a rule fails
@@ -261,8 +261,8 @@ use ProgrammatorDev\YetAnotherPhpValidator\Validator;
261261
262262Validator::choice(
263263 constraints: ['red', 'green', 'blue'],
264- message: '" {{ value }}" is not a valid {{ name }}! You must select one of {{ constraints }}.'
264+ message: '{{ value }} is not a valid {{ name }}! You must select one of {{ constraints }}.'
265265)->assert('yellow', 'color');
266266
267- // Throws: "yellow" is not a valid color! You must select one of [red, green, blue].
267+ // Throws: "yellow" is not a valid color! You must select one of [" red", " green", " blue" ].
268268```
0 commit comments