RequestUrlAccess::getValueFromUrlPlaceholder()   B
last analyzed

Complexity

Conditions 11
Paths 11

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 23
cts 23
cp 1
rs 7.3166
c 0
b 0
f 0
cc 11
nc 11
nop 2
crap 11

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 Mcustiel\PowerRoute\Common;
4
5
use Psr\Http\Message\UriInterface;
6
7
trait RequestUrlAccess
8
{
9 11
    private function getValueFromUrlPlaceholder($name, UriInterface $uri)
10
    {
11
        switch ($name) {
12 11
            case 'full':
13 11
            case null:
14 2
                return $uri->__toString();
15 9
            case 'host':
16 1
                return $uri->getHost();
17 8
            case 'scheme':
18 1
                return $uri->getScheme();
19 7
            case 'authority':
20 1
                return $uri->getAuthority();
21 6
            case 'fragment':
22 1
                return $uri->getFragment();
23 5
            case 'path':
24 1
                return $uri->getPath();
25 4
            case 'port':
26 1
                return $uri->getPort();
27 3
            case 'query':
28 1
                return $uri->getQuery();
29 2
            case 'user-info':
30 1
                return $uri->getUserInfo();
31 1
            default:
32 1
                throw new \Exception('Invalid config');
33 1
        }
34
    }
35
}
36