• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tochka-developers / jsonrpc / 4144901857

pending completion
4144901857

push

github

darkdarin
feat: add tests

29 of 31 new or added lines in 7 files covered. (93.55%)

441 of 1323 relevant lines covered (33.33%)

2.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/Exceptions/ValidationException.php
1
<?php
2

3
namespace Tochka\JsonRpc\Exceptions;
4

5
use Illuminate\Validation\Validator;
6
use Tochka\JsonRpc\Standard\Exceptions\Additional\InvalidParametersException;
7
use Tochka\JsonRpc\Standard\Exceptions\Errors\InvalidParameterError;
8
use Tochka\JsonRpc\Standard\Exceptions\Errors\InvalidParametersError;
9

10
class ValidationException extends InvalidParametersException
11
{
12
    public function __construct(Validator $validator, ?\Throwable $previous = null)
13
    {
14
        $errors = new InvalidParametersError(
3✔
15
            $this->getJsonRpcErrors($validator)
3✔
16
        );
3✔
17

18
        parent::__construct($errors, $previous);
3✔
19
    }
20

21
    /**
22
     * @param Validator $validator
23
     * @return array<InvalidParameterError>
24
     */
25
    public function getJsonRpcErrors(Validator $validator): array
26
    {
27
        $errors = [];
3✔
28

29
        /** @var array<string, array<string, array>> $failedRules */
30
        $failedRules = $validator->failed();
3✔
31
        $failedMessages = $validator->getMessageBag();
3✔
32

33
        foreach ($failedRules as $attributeName => $rule) {
3✔
34
            /** @var array<array-key, string> $attributeMessages */
35
            $attributeMessages = $failedMessages->get($attributeName);
3✔
36

37
            foreach ($rule as $ruleName => $_) {
3✔
38
                if (count($attributeMessages) === 0) {
3✔
NEW
39
                    $message = $ruleName;
×
40
                } else {
41
                    $message = array_shift($attributeMessages);
3✔
42
                }
43

44

45

46
                /** @psalm-suppress MixedArgument */
47
                $errors[] = new InvalidParameterError($attributeName, $ruleName, $message);
3✔
48
            }
49
        }
50

51
        return $errors;
3✔
52
    }
53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc