Completed
Branch master (ed410a)
by Mariano
03:14
created

RequestUrlAccess::getValueFromUrlPlaceholder()   C

Complexity

Conditions 11
Paths 11

Size

Total Lines 26
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 11

Importance

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