JsonSchemaRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
c 1
b 0
f 0
dl 0
loc 36
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A failedValidation() 0 3 1
A validated() 0 3 1
A getValidatorInstance() 0 11 2
A setContainer() 0 5 1
1
<?php
2
3
namespace Webtools\JsonSchemaRequest;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Contracts\Validation\ValidatesWhenResolved;
7
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
8
use Illuminate\Http\Request;
9
use Illuminate\Validation\ValidatesWhenResolvedTrait;
10
use Webtools\JsonSchemaRequest\Exceptions\ValidationException;
11
use Webtools\JsonSchemaRequest\Validation\JsonSchemaValidator;
12
13
class JsonSchemaRequest extends Request implements ValidatesWhenResolved
14
{
15
    use ValidatesWhenResolvedTrait;
16
17
    protected Container $container;
18
19
    protected ?ValidatorContract $validator = null;
20
21 2
    public function getValidatorInstance()
22
    {
23 2
        if (!$this->validator) {
24 2
            $this->validator = new JsonSchemaValidator(
25 2
                $this->container->make(\JsonSchema\Validator::class),
26 2
                $this->container->call([$this, 'schema']),
0 ignored issues
show
Bug introduced by
It seems like $this->container->call(array($this, 'schema')) can also be of type callable; however, parameter $schema of Webtools\JsonSchemaReque...alidator::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
                /** @scrutinizer ignore-type */ $this->container->call([$this, 'schema']),
Loading history...
27 2
                $this->json()->all(),
28
            );
29
        }
30
31 2
        return $this->validator;
32
    }
33
34 2
    public function setContainer(Container $container)
35
    {
36 2
        $this->container = $container;
37
38 2
        return $this;
39
    }
40
41 1
    public function failedValidation(JsonSchemaValidator $validator)
42
    {
43 1
        throw new ValidationException($validator);
44
    }
45
46 1
    public function validated()
47
    {
48 1
        return $this->validator->validated();
0 ignored issues
show
Bug introduced by
The method validated() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        return $this->validator->/** @scrutinizer ignore-call */ validated();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
    }
50
}
51