Completed
Pull Request — master (#34)
by Billie
07:57
created

AllOfGuesser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Joli\Jane\OpenApi\Guesser\OpenApiSchema;
4
5
use Joli\Jane\Guesser\JsonSchema\AllOfGuesser as BaseAllOfGuesser;
6
use Joli\Jane\Guesser\PropertiesGuesserInterface;
7
use Joli\Jane\OpenApi\Model\Schema;
8
use Joli\Jane\Reference\Resolver;
9
use Joli\Jane\Runtime\Reference;
10
11
class AllOfGuesser extends BaseAllOfGuesser implements PropertiesGuesserInterface
12
{
13 4
    /**
14
     * @var Resolver
15 4
     */
16
    private $resolver;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
17
18
    /**
19
     * AllOfGuesser constructor.
20
     *
21
     * @param Resolver $resolver
22
     */
23
    public function __construct(Resolver $resolver)
24
    {
25
        $this->resolver = $resolver;
26
27
        parent::__construct($resolver);
28
    }
29
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function supportObject($object)
35
    {
36
        return (($object instanceof Schema) && is_array($object->getAllOf()) && count($object->getAllOf()) > 0);
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\Schema does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
37
    }
38
39
    /**
40
     * Return all properties guessed
41
     *
42
     * @param Schema                                $object
43
     * @param string                                $name
44
     * @param \Joli\Jane\Guesser\Guess\ClassGuess[] $classes
45
     *
46
     * @return \Joli\Jane\Guesser\Guess\Property[]
47
     */
48
    public function guessProperties($object, $name, $classes)
49
    {
50
        $properties = [];
51
52
        foreach ($object->getAllOf() as $allOfSchema) {
53
            if ($allOfSchema instanceof Reference) {
54
                $allOfSchema = $this->resolver->resolve($allOfSchema);
55
            }
56
57
            $properties = array_merge($properties, $this->chainGuesser->guessProperties($allOfSchema, $name, $classes));
58
        }
59
60
        return $properties;
61
    }
62
}
63