Total Complexity | 4 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types = 1); |
||
11 | class ServiceProvider extends BaseServiceProvider |
||
12 | { |
||
13 | public function boot() |
||
14 | { |
||
15 | $this->publishes( |
||
16 | [ |
||
17 | __DIR__.'/../config/json_schema_validator.php' => config_path('json_schema_validator.php'), |
||
18 | ], |
||
19 | 'json_schema_validator' |
||
20 | ); |
||
21 | |||
22 | BaseValidator::extend('json_schema_validator', static function ($attribute, $value, $parameters, $validator) { |
||
|
|||
23 | if (count($parameters) != 1) { |
||
24 | throw ValidationException::withMessages([ |
||
25 | 'json_schema_validator' => JsonSchemaValidatorException::INVALID_PARAMETERS_QUANTITY, |
||
26 | ]); |
||
27 | } |
||
28 | |||
29 | $filePath = config('json_schema_validator.storage_path') . '/' . $parameters[0]; |
||
30 | |||
31 | try { |
||
32 | $JsonValidate = new JsonSchemaValidator(); |
||
33 | |||
34 | $JsonValidate->setSchema($filePath); |
||
35 | $JsonValidate->setData($value); |
||
36 | |||
37 | return $JsonValidate->validate(); |
||
38 | } catch (Exception $e) { |
||
39 | throw ValidationException::withMessages([ |
||
40 | 'json_schema_validator' => $e->getMessage(), |
||
41 | ]); |
||
42 | } |
||
43 | }); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Make config publishment optional by merging the config from the package. |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function register() |
||
56 | ); |
||
57 | } |
||
59 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.