Completed
Push — master ( 22a756...a8d83f )
by John
02:03
created

ParameterTypePatternResolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C resolve() 0 28 7
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
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...
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
}