These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php declare(strict_types = 1); |
||
2 | /* |
||
3 | * This file is part of the KleijnWeb\PhpApi\Descriptions 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\PhpApi\Middleware\Util; |
||
9 | |||
10 | use KleijnWeb\PhpApi\Descriptions\Description\Schema\ScalarSchema; |
||
11 | use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema; |
||
12 | |||
13 | class ParameterTypePatternResolver |
||
14 | { |
||
15 | /** |
||
16 | * @param Schema $schema |
||
17 | * @return string |
||
18 | */ |
||
19 | public function resolve(Schema $schema): string |
||
20 | { |
||
21 | $typePattern = '.*'; |
||
22 | |||
23 | switch ($type = $schema->getType()) { |
||
0 ignored issues
–
show
|
|||
24 | case Schema::TYPE_INT: |
||
25 | $typePattern = '\d+'; |
||
26 | break; |
||
27 | case Schema::TYPE_NUMBER: |
||
28 | $typePattern = '\d+(\.\d+)?'; |
||
29 | break; |
||
30 | case Schema::TYPE_NULL: |
||
31 | $typePattern = 'null'; |
||
32 | break; |
||
33 | case Schema::TYPE_STRING: |
||
34 | /** @var $schema ScalarSchema $routeString */ |
||
35 | if ($pattern = $schema->getPattern()) { |
||
36 | $typePattern = $pattern; |
||
37 | } elseif ($enum = $schema->getEnum()) { |
||
38 | $typePattern = '('.implode('|', $enum).')'; |
||
39 | } |
||
40 | break; |
||
41 | default: |
||
42 | return $typePattern; |
||
43 | } |
||
44 | |||
45 | return $typePattern; |
||
46 | } |
||
47 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.