PluginProbe
Metricool – Social media and site statistics / trunk
Metricool – Social media and site statistics vtrunk
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Exceptions / ValidationException.php

ValidationException.php in Metricool – Social media and site statistics trunk, at app/Exceptions/ValidationException.php

34 lines 711 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Metricool\Exceptions;
6
7 /**
8 * Exception thrown when validation of request data fails.
9 * @see \Metricool\Support\Validation\Validator
10 */
11 class ValidationException extends RestDataException
12 {
13 protected int $statusCode = 422;
14
15 /**
16 * Create a new instance with the given validation errors.
17 */
18 public static function withErrors(array $errors): self
19 {
20 $instance = new self(__('Validation failed.', 'metricool'));
21 $instance->setData($errors);
22
23 return $instance;
24 }
25
26 /**
27 * Get the validation errors, keyed by field name.
28 */
29 public function errors(): array
30 {
31 return $this->getData();
32 }
33 }
34