Completed
Push — master ( fcd315...e54b6a )
by John
02:20
created

OpenApiFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\ApiDescriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace KleijnWeb\ApiDescriptions\Description\OpenApi;
9
10
use KleijnWeb\ApiDescriptions\Description\Description;
11
use KleijnWeb\ApiDescriptions\Description\Factory\StandardFactory;
12
use KleijnWeb\ApiDescriptions\Description\OpenApi\OpenApiDescription;
13
use KleijnWeb\ApiDescriptions\Document\Document;
14
use KleijnWeb\ApiDescriptions\Document\Definition\RefResolver\RefResolver;
15
use KleijnWeb\ApiDescriptions\Document\Definition\Validator\DefinitionValidator;
16
17
/**
18
 * @author John Kleijn <[email protected]>
19
 */
20
class OpenApiFactory implements StandardFactory
21
{
22
    /**
23
     * @var DefinitionValidator|null
24
     */
25
    private $validator;
26
27
    /**
28
     * Repository constructor.
29
     *
30
     * @param DefinitionValidator|null $validator
31
     */
32
    public function __construct(DefinitionValidator $validator = null)
33
    {
34
        $this->validator = $validator;
35
    }
36
37
    /**
38
     * @param string    $uri
39
     * @param \stdClass $definition
40
     *
41
     * @return Description
42
     */
43
    public function build(string $uri, \stdClass $definition): Description
44
    {
45
        $resolver = new RefResolver($definition, $uri);
46
47
        /** @var \stdClass $definition */
48
        $description = new OpenApiDescription(new Document($uri, $definition = $resolver->resolve()));
49
50
        if ($this->validator) {
51
            $this->validator->validate($definition);
0 ignored issues
show
Documentation introduced by
$definition is of type object|array, but the function expects a object<stdClass>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
        }
53
54
        return $description;
55
    }
56
}
57