Completed
Push — master ( 1c6d46...3dbc46 )
by Joel
10:24
created

InputGeneratorTrait::resolveParameter()   C

Complexity

Conditions 11
Paths 1

Size

Total Lines 22
Code Lines 13

Duplication

Lines 15
Ratio 68.18 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
dl 15
loc 22
ccs 0
cts 0
cp 0
rs 5.9012
c 0
b 0
f 0
cc 11
eloc 13
nc 1
nop 1
crap 132

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Joli\Jane\OpenApi\Generator;
4
5
use Doctrine\Common\Inflector\Inflector;
6
use Joli\Jane\Generator\Context\Context;
7
use Joli\Jane\Runtime\Reference;
8
use Joli\Jane\OpenApi\Model\BodyParameter;
9
use Joli\Jane\OpenApi\Model\FormDataParameterSubSchema;
10
use Joli\Jane\OpenApi\Model\HeaderParameterSubSchema;
11
use Joli\Jane\OpenApi\Model\PathParameterSubSchema;
12
use Joli\Jane\OpenApi\Model\QueryParameterSubSchema;
13
use Joli\Jane\OpenApi\Operation\Operation;
14
use Joli\Jane\Reference\Resolver;
15
use PhpParser\Node\Arg;
16
use PhpParser\Node\Expr;
17
use PhpParser\Node\Name;
18
use PhpParser\Node\Param;
19
use PhpParser\Node\Scalar;
20
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
21
22
trait InputGeneratorTrait
23
{
24
    /**
25
     * @var Parameter\BodyParameterGenerator
26
     */
27
    protected $bodyParameterGenerator;
28
29
    /**
30
     * @var Parameter\FormDataParameterGenerator
31
     */
32
    protected $formDataParameterGenerator;
33
34
    /**
35
     * @var Parameter\HeaderParameterGenerator
36
     */
37
    protected $headerParameterGenerator;
38
39
    /**
40
     * @var Parameter\PathParameterGenerator
41
     */
42
    protected $pathParameterGenerator;
43
44
    /**
45
     * @var Parameter\QueryParameterGenerator
46
     */
47
    protected $queryParameterGenerator;
48
49
    /**
50
     * @return DenormalizerInterface
51
     */
52
    abstract protected function getDenormalizer();
53
54
    /**
55
     * Create the query param statements and documentation
56
     *
57
     * @param Operation $operation
58
     *
59
     * @return array
60 7
     */
61
    protected function createQueryParamStatements(Operation $operation)
62 7
    {
63 7
        $queryParamDocumentation = [];
64
        $queryParamVariable = new Expr\Variable('queryParam');
65 7
        $queryParamStatements = [
66 7
            new Expr\Assign($queryParamVariable, new Expr\New_(new Name('QueryParam')))
67
        ];
68 7
69 3
        if ($operation->getOperation()->getParameters()) {
70 3
            foreach ($operation->getOperation()->getParameters() as $parameter) {
71 1
                if ($parameter instanceof Reference) {
72 1
                    $parameter = $this->resolveParameter($parameter);
73
                }
74 3
75 1 View Code Duplication
                if ($parameter instanceof FormDataParameterSubSchema) {
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\FormDataParameterSubSchema 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...
Duplication introduced by
This code seems to be duplicated across 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...
76 1
                    $queryParamStatements = array_merge($queryParamStatements, $this->formDataParameterGenerator->generateQueryParamStatements($parameter, $queryParamVariable));
77 1
                    $queryParamDocumentation[] = $this->formDataParameterGenerator->generateQueryDocParameter($parameter);
78
                }
79 3
80 1 View Code Duplication
                if ($parameter instanceof HeaderParameterSubSchema) {
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\HeaderParameterSubSchema 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...
Duplication introduced by
This code seems to be duplicated across 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...
81 1
                    $queryParamStatements = array_merge($queryParamStatements, $this->headerParameterGenerator->generateQueryParamStatements($parameter, $queryParamVariable));
82 1
                    $queryParamDocumentation[] = $this->headerParameterGenerator->generateQueryDocParameter($parameter);
83
                }
84 3
85 1 View Code Duplication
                if ($parameter instanceof QueryParameterSubSchema) {
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\QueryParameterSubSchema 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...
Duplication introduced by
This code seems to be duplicated across 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...
86 1
                    $queryParamStatements = array_merge($queryParamStatements, $this->queryParameterGenerator->generateQueryParamStatements($parameter, $queryParamVariable));
87 1
                    $queryParamDocumentation[] = $this->queryParameterGenerator->generateQueryDocParameter($parameter);
88 3
                }
89 3
            }
90
        }
91 7
92
        return [$queryParamDocumentation, $queryParamStatements, $queryParamVariable];
93
    }
94
95
    /**
96
     * Create parameters for the method and their documentation
97
     *
98
     * @param Operation $operation
99
     * @param string[]  $queryParamDocumentation
100
     * @param Context   $context
101
     *
102
     * @return array
103 7
     */
104
    protected function createParameters(Operation $operation, $queryParamDocumentation, Context $context)
105 7
    {
106 7
        $documentationParams = [];
107
        $methodParameters = [];
108 7
109 3
        if ($operation->getOperation()->getParameters()) {
110 3 View Code Duplication
            foreach ($operation->getOperation()->getParameters() as $parameter) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
111 1
                if ($parameter instanceof Reference) {
112 1
                    $parameter = $this->resolveParameter($parameter);
113
                }
114 3
115 1
                if ($parameter instanceof PathParameterSubSchema) {
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\PathParameterSubSchema 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...
116 1
                    $methodParameters[] = $this->pathParameterGenerator->generateMethodParameter($parameter, $context);
117 1
                    $documentationParams[] = sprintf(' * @param %s', $this->pathParameterGenerator->generateDocParameter($parameter, $context));
118 3
                }
119
            }
120 3
121 3 View Code Duplication
            foreach ($operation->getOperation()->getParameters() as $parameter) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
122 1
                if ($parameter instanceof Reference) {
123 1
                    $parameter = $this->resolveParameter($parameter);
124
                }
125 3
126 2
                if ($parameter instanceof BodyParameter) {
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\BodyParameter 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...
127 2
                    $methodParameters[] = $this->bodyParameterGenerator->generateMethodParameter($parameter, $context);
128 2
                    $documentationParams[] = sprintf(' * @param %s', $this->bodyParameterGenerator->generateDocParameter($parameter, $context));
129 3
                }
130 3
            }
131
        }
132 7
133 1
        if (!empty($queryParamDocumentation)) {
134
            $documentationParams[] = " * @param array  \$parameters {";
135 1
            $documentationParams   = array_merge($documentationParams, array_map(function ($doc) {
136 1
                return " *     " . $doc;
137 1
            }, $queryParamDocumentation));
138 1
            $documentationParams[] = " * }";
139 7
        } else {
140
            $documentationParams[] = " * @param array  \$parameters List of parameters";
141
        }
142 7
143
        $documentationParams[] = " * @param string \$fetch      Fetch mode (object or response)";
144 7
145 7
        $methodParameters[] = new Param('parameters', new Expr\Array_());
146
        $methodParameters[] = new Param('fetch', new Expr\ConstFetch(new Name('self::FETCH_OBJECT')));
147 7
148
        return [$documentationParams, $methodParameters];
149
    }
150
151
    /**
152
     * Create all statements around url transformation
153
     *
154
     * @param Operation $operation
155
     * @param Expr\Variable $queryParamVariable
156
     *
157
     * @return array
158 7
     */
159
    protected function createUrlStatements(Operation $operation, $queryParamVariable)
160 7
    {
161
        $urlVariable = new Expr\Variable('url');
162
        // url = /path
163 7
        $statements = [
164 7
            new Expr\Assign($urlVariable, new Scalar\String_($operation->getPath()))
165
        ];
166 7
167 3
        if ($operation->getOperation()->getParameters()) {
168 3
            foreach ($operation->getOperation()->getParameters() as $parameter) {
169 1
                if ($parameter instanceof Reference) {
170 1
                    $parameter = $this->resolveParameter($parameter);
171
                }
172 3
173
                if ($parameter instanceof PathParameterSubSchema) {
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\PathParameterSubSchema 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...
174 1
                    // $url = str_replace('{param}', $param, $url)
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
175 1
                    $statements[] = new Expr\Assign($urlVariable, new Expr\FuncCall(new Name('str_replace'), [
176 1
                        new Arg(new Scalar\String_('{' . $parameter->getName() . '}')),
177 1
                        new Arg(new Expr\FuncCall(new Name('urlencode'), [
178 1
                            new Arg(new Expr\Variable(Inflector::camelize($parameter->getName()))),
179 1
                        ])),
180 1
                        new Arg($urlVariable)
181 1
                    ]));
182 3
                }
183 3
            }
184
        }
185
186 7
        // url = url . ? . $queryParam->buildQueryString
187 7
        $statements[] = new Expr\Assign($urlVariable, new Expr\BinaryOp\Concat(
188 7
            $urlVariable,
189 7
            new Expr\BinaryOp\Concat(
190 7
                new Scalar\String_('?'),
191 7
                new Expr\MethodCall($queryParamVariable, 'buildQueryString', [new Arg(new Expr\Variable('parameters'))])
192 7
            )
193
        ));
194 7
195
        return [$statements, $urlVariable];
196
    }
197
198
    /**
199
     * Create body statements
200
     *
201
     * @param Operation $operation
202
     * @param Expr\Variable $queryParamVariable
203
     * @param Context $context
204
     *
205
     * @return array
206 7
     */
207
    protected function createBodyStatements(Operation $operation, $queryParamVariable, Context $context)
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
208 7
    {
209 7
        $bodyParameter = null;
210
        $bodyVariable = new Expr\Variable('body');
211 7
212 3
        if ($operation->getOperation()->getParameters()) {
213 3
            foreach ($operation->getOperation()->getParameters() as $parameter) {
214 2
                if ($parameter instanceof BodyParameter) {
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\BodyParameter 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...
215 2
                    $bodyParameter = $parameter;
216 3
                }
217 3
            }
218
        }
219 7
220
        if (null === $bodyParameter) {
221
            // $body = $queryParam->buildFormDataString($parameters);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
222 6
            return [[
223 6
                new Expr\Assign($bodyVariable, new Expr\MethodCall($queryParamVariable, 'buildFormDataString', [new Arg(new Expr\Variable('parameters'))]))
224
            ], $bodyVariable];
225
        }
226
227 2
        // $body = $parameter
228
        if (!($bodyParameter->getSchema() instanceof Reference)) {
229 2
            return [[
230 2
                new Expr\Assign($bodyVariable, new Expr\Variable(Inflector::camelize($bodyParameter->getName())))
231
            ], $bodyVariable];
232
        }
233
234
        // $body = $this->serializer->serialize($parameter);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
235
        return [
236 1
            [
237 1
                new Expr\Assign(
238 1
                    $bodyVariable,
239 1
                    new Expr\MethodCall(
240 1
                        new Expr\PropertyFetch(new Expr\Variable('this'), 'serializer'),
241
                        'serialize',
242 1
                        [
243 1
                            new Arg(new Expr\Variable(Inflector::camelize($bodyParameter->getName()))),
244 1
                            new Arg(new Scalar\String_('json'))
245 1
                        ]
246 1
                    )
247 1
                )
248
            ],
249 1
            $bodyVariable
250
        ];
251
    }
252
253
    /**
254
     * Create headers statements
255
     *
256
     * @param Operation $operation
257
     * @param Expr\Variable $queryParamVariable
258
     *
259
     * @return array
260 7
     */
261
    protected function createHeaderStatements(Operation $operation, $queryParamVariable)
262 7
    {
263
        $headerVariable = new Expr\Variable('headers');
264
265 7
        $headers = [
266 7
            new Expr\ArrayItem(
267 7
                new Scalar\String_($operation->getHost()),
268 7
                new Scalar\String_('Host')
269 7
            ),
270
        ];
271 7
272
        $produces = $operation->getOperation()->getProduces();
273 7
274 1
        if ($produces && in_array("application/json", $produces)) {
275 1
            $headers[]
276 1
                = new Expr\ArrayItem(
277
                    new Expr\Array_(
278 1
                        [
279 1
                        new Expr\ArrayItem(
280 1
                            new Scalar\String_("application/json")
281
                        ),
282 1
                        ]
283 1
                    ),
284 1
                    new Scalar\String_('Accept')
285 1
                );
286
        }
287 7
288
        $consumes = $operation->getOperation()->getProduces();
289 7
290 1
        if ($operation->getOperation()->getParameters() && $consumes) {
291 1
            $bodyParameters = array_filter(
292 1
                $operation->getOperation()->getParameters(),
293 1
                function ($parameter) {
294
                    return $parameter instanceof BodyParameter;
0 ignored issues
show
Bug introduced by
The class Joli\Jane\OpenApi\Model\BodyParameter 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...
295 1
                }
296
            );
297 1
298 1
            if (count($bodyParameters) > 0 && in_array("application/json", $consumes)) {
299 1
                $headers[]
300 1
                    = new Expr\ArrayItem(
301 1
                        new Scalar\String_("application/json"),
302 1
                        new Scalar\String_('Content-Type')
303 1
                    );
304 1
            }
305
        }
306
307
        return [
308 7
            [
309 7
                new Expr\Assign(
310 7
                    $headerVariable,
311 7
                    new Expr\FuncCall(new Name('array_merge'), [
312 7
                        new Arg(
313
                            new Expr\Array_(
314 7
                                $headers
315 7
                            )
316 7
                        ),
317 7
                        new Arg(new Expr\MethodCall($queryParamVariable, 'buildHeaders', [new Arg(new Expr\Variable('parameters'))]))
318 7
                    ])
319 7
                )
320
            ],
321 7
            $headerVariable
322
        ];
323
    }
324
325
    /**
326
     * @param Reference $parameter
327
     *
328
     * @return BodyParameter|HeaderParameterSubSchema|FormDataParameterSubSchema|QueryParameterSubSchema|PathParameterSubSchema
329
     */
330
    protected function resolveParameter(Reference $parameter)
331
    {
332
        return $parameter->resolve(function ($value) {
333 View Code Duplication
            if (isset($value->{'in'}) and $value->{'in'} == 'body') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
334
                return $this->getDenormalizer()->denormalize($value, 'Joli\\Jane\\OpenApi\\Model\\BodyParameter');
335
            }
336 View Code Duplication
            if (isset($value->{'in'}) and $value->{'in'} == 'header') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
337
                return $this->getDenormalizer()->denormalize($value, 'Joli\\Jane\\OpenApi\\Model\\HeaderParameterSubSchema');
338
            }
339 View Code Duplication
            if (isset($value->{'in'}) and $value->{'in'} == 'formData') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
340
                return $this->getDenormalizer()->denormalize($value, 'Joli\\Jane\\OpenApi\\Model\\FormDataParameterSubSchema');
341
            }
342 View Code Duplication
            if (isset($value->{'in'}) and $value->{'in'} == 'query') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
343
                return $this->getDenormalizer()->denormalize($value, 'Joli\\Jane\\OpenApi\\Model\\QueryParameterSubSchema');
344
            }
345 View Code Duplication
            if (isset($value->{'in'}) and $value->{'in'} == 'path') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
346
                return $this->getDenormalizer()->denormalize($value, 'Joli\\Jane\\OpenApi\\Model\\PathParameterSubSchema');
347
            }
348
349
            return $value;
350
        });
351
    }
352
}
353