Completed
Push — master ( 4de09a...56e82d )
by Loick
11s
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 8
CRAP Score 17.8835

Importance

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

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
     */
61 8
    protected function createQueryParamStatements(Operation $operation)
62
    {
63 8
        $queryParamDocumentation = [];
64 8
        $queryParamVariable = new Expr\Variable('queryParam');
65
        $queryParamStatements = [
66 8
            new Expr\Assign($queryParamVariable, new Expr\New_(new Name('QueryParam')))
67 8
        ];
68
69 8
        if ($operation->getOperation()->getParameters()) {
70 3
            foreach ($operation->getOperation()->getParameters() as $parameter) {
71 3
                if ($parameter instanceof Reference) {
72 1
                    $parameter = $this->resolveParameter($parameter);
73 1
                }
74
75 3 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 1
                }
79
80 3 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 1
                }
84
85 3 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 1
                }
89 3
            }
90 3
        }
91
92 8
        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
     */
104 8
    protected function createParameters(Operation $operation, $queryParamDocumentation, Context $context)
105
    {
106 8
        $documentationParams = [];
107 8
        $methodParameters = [];
108
109 8
        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 3
                if ($parameter instanceof Reference) {
112 1
                    $parameter = $this->resolveParameter($parameter);
113 1
                }
114
115 3
                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 1
                }
119 3
            }
120
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 3
                if ($parameter instanceof Reference) {
123 1
                    $parameter = $this->resolveParameter($parameter);
124 1
                }
125
126 3
                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 2
                }
130 3
            }
131 3
        }
132
133 8
        if (!empty($queryParamDocumentation)) {
134 1
            $documentationParams[] = " * @param array  \$parameters {";
135
            $documentationParams   = array_merge($documentationParams, array_map(function ($doc) {
136 1
                return " *     " . $doc;
137 1
            }, $queryParamDocumentation));
138 1
            $documentationParams[] = " * }";
139 1
        } else {
140 8
            $documentationParams[] = " * @param array  \$parameters List of parameters";
141
        }
142
143 8
        $documentationParams[] = " * @param string \$fetch      Fetch mode (object or response)";
144
145 8
        $methodParameters[] = new Param('parameters', new Expr\Array_());
146 8
        $methodParameters[] = new Param('fetch', new Expr\ConstFetch(new Name('self::FETCH_OBJECT')));
147
148 8
        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
     */
159 8
    protected function createUrlStatements(Operation $operation, $queryParamVariable)
160
    {
161 8
        $urlVariable = new Expr\Variable('url');
162
        // url = /path
163
        $statements = [
164 8
            new Expr\Assign($urlVariable, new Scalar\String_($operation->getPath()))
165 8
        ];
166
167 8
        if ($operation->getOperation()->getParameters()) {
168 3
            foreach ($operation->getOperation()->getParameters() as $parameter) {
169 3
                if ($parameter instanceof Reference) {
170 1
                    $parameter = $this->resolveParameter($parameter);
171 1
                }
172
173 3
                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
                    // $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 1
                }
183 3
            }
184 3
        }
185
186
        // url = url . ? . $queryParam->buildQueryString
187 8
        $statements[] = new Expr\Assign($urlVariable, new Expr\BinaryOp\Concat(
188 8
            $urlVariable,
189 8
            new Expr\BinaryOp\Concat(
190 8
                new Scalar\String_('?'),
191 8
                new Expr\MethodCall($queryParamVariable, 'buildQueryString', [new Arg(new Expr\Variable('parameters'))])
192 8
            )
193 8
        ));
194
195 8
        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
     */
207 8
    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
    {
209 8
        $bodyParameter = null;
210 8
        $bodyVariable = new Expr\Variable('body');
211
212 8
        if ($operation->getOperation()->getParameters()) {
213 3
            foreach ($operation->getOperation()->getParameters() as $parameter) {
214 3
                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 2
                }
217 3
            }
218 3
        }
219
220 8
        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
            return [[
223 7
                new Expr\Assign($bodyVariable, new Expr\MethodCall($queryParamVariable, 'buildFormDataString', [new Arg(new Expr\Variable('parameters'))]))
224 7
            ], $bodyVariable];
225
        }
226
227
        // $body = $parameter
228 2
        if (!($bodyParameter->getSchema() instanceof Reference)) {
229
            return [[
230 2
                new Expr\Assign($bodyVariable, new Expr\Variable(Inflector::camelize($bodyParameter->getName())))
231 2
            ], $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
            [
237 1
                new Expr\Assign(
238 1
                    $bodyVariable,
239 1
                    new Expr\MethodCall(
240 1
                        new Expr\PropertyFetch(new Expr\Variable('this'), 'serializer'),
241 1
                        'serialize',
242
                        [
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 1
            ],
249
            $bodyVariable
250 1
        ];
251
    }
252
253
    /**
254
     * Create headers statements
255
     *
256
     * @param Operation $operation
257
     * @param Expr\Variable $queryParamVariable
258
     *
259
     * @return array
260
     */
261 8
    protected function createHeaderStatements(Operation $operation, $queryParamVariable)
262
    {
263 8
        $headerVariable = new Expr\Variable('headers');
264
265
        $headers = [
266 8
            new Expr\ArrayItem(
267 8
                new Scalar\String_($operation->getHost()),
268 8
                new Scalar\String_('Host')
269 8
            ),
270 8
        ];
271
272 8
        $produces = $operation->getOperation()->getProduces();
273
274 8
        if ($produces && in_array("application/json", $produces)) {
275 1
            $headers[]
276 1
                = new Expr\ArrayItem(
277 1
                    new Expr\Array_(
278
                        [
279 1
                        new Expr\ArrayItem(
280 1
                            new Scalar\String_("application/json")
281 1
                        ),
282
                        ]
283 1
                    ),
284 1
                    new Scalar\String_('Accept')
285 1
                );
286 1
        }
287
288 8
        $consumes = $operation->getOperation()->getProduces();
289
290 8
        if ($operation->getOperation()->getParameters() && $consumes) {
291 1
            $bodyParameters = array_filter(
292 1
                $operation->getOperation()->getParameters(),
293
                function ($parameter) {
294 1
                    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
                }
296 1
            );
297
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 1
        }
306
307
        return [
308
            [
309 8
                new Expr\Assign(
310 8
                    $headerVariable,
311 8
                    new Expr\FuncCall(new Name('array_merge'), [
312 8
                        new Arg(
313 8
                            new Expr\Array_(
314
                                $headers
315 8
                            )
316 8
                        ),
317 8
                        new Arg(new Expr\MethodCall($queryParamVariable, 'buildHeaders', [new Arg(new Expr\Variable('parameters'))]))
318 8
                    ])
319 8
                )
320 8
            ],
321
            $headerVariable
322 8
        ];
323
    }
324
325
    /**
326
     * @param Reference $parameter
327
     *
328
     * @return BodyParameter|HeaderParameterSubSchema|FormDataParameterSubSchema|QueryParameterSubSchema|PathParameterSubSchema
329
     */
330
    protected function resolveParameter(Reference $parameter)
331
    {
332 1
        return $parameter->resolve(function ($value) {
333 1 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 1 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 1 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 1 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 1 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 1
                return $this->getDenormalizer()->denormalize($value, 'Joli\\Jane\\OpenApi\\Model\\PathParameterSubSchema');
347
            }
348
349
            return $value;
350 1
        });
351
    }
352
}
353