Completed
Push — master ( 6e1c48...7d90f1 )
by John
03:00
created

ParameterTypePatternResolver::resolve()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 28
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 21
nc 7
nop 1
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
9
namespace KleijnWeb\PhpApi\Descriptions\Util;
10
11
use KleijnWeb\PhpApi\Descriptions\Description\Schema\ScalarSchema;
12
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
13
14
class ParameterTypePatternResolver
15
{
16
    /**
17
     * @param Schema $schema
18
     * @return string
19
     */
20
    public function resolve(Schema $schema): string
21
    {
22
        $typePattern = '.*';
23
24
        switch ($type = $schema->getType()) {
0 ignored issues
show
Unused Code introduced by
$type is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
25
            case Schema::TYPE_INT:
26
                $typePattern = '\d+';
27
                break;
28
            case Schema::TYPE_NUMBER:
29
                $typePattern = '\d+(\.\d+)?';
30
                break;
31
            case Schema::TYPE_NULL:
32
                $typePattern = 'null';
33
                break;
34
            case Schema::TYPE_STRING:
35
                /** @var $schema ScalarSchema $routeString */
36
                if ($pattern = $schema->getPattern()) {
37
                    $typePattern = $pattern;
38
                } elseif ($enum = $schema->getEnum()) {
39
                    $typePattern = '(' . implode('|', $enum) . ')';
40
                }
41
                break;
42
            default:
43
                return $typePattern;
44
        }
45
46
        return $typePattern;
47
    }
48
}
49