Completed
Push — master ( e54b6a...c762b0 )
by John
03:11
created

RamlFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
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\Standard\Raml;
9
10
use KleijnWeb\ApiDescriptions\Description\Description;
11
use KleijnWeb\ApiDescriptions\Description\Factory\StandardFactory;
12
use KleijnWeb\ApiDescriptions\Document\Definition\RefResolver\RefResolver;
13
use KleijnWeb\ApiDescriptions\Document\Definition\Validator\DefinitionValidator;
14
use KleijnWeb\ApiDescriptions\Document\Document;
15
16
/**
17
 * @author John Kleijn <[email protected]>
18
 */
19 View Code Duplication
class RamlFactory implements StandardFactory
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * @var DefinitionValidator|null
23
     */
24
    private $validator;
25
26
    /**
27
     * Repository constructor.
28
     *
29
     * @param DefinitionValidator|null $validator
30
     */
31
    public function __construct(DefinitionValidator $validator = null)
32
    {
33
        $this->validator = $validator;
34
    }
35
36
    /**
37
     * @param string    $uri
38
     * @param \stdClass $definition
39
     *
40
     * @return Description
41
     */
42
    public function build(string $uri, \stdClass $definition): Description
43
    {
44
        $resolver = new RefResolver($definition, $uri);
45
46
        /** @var \stdClass $definition */
47
        $description = new RamlDescription(new Document($uri, $definition = $resolver->resolve()));
48
49
        if ($this->validator) {
50
            $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...
51
        }
52
53
        return $description;
54
    }
55
}
56