Completed
Push — develop ( 7fa98c...fc74bf )
by Risan Bagja
01:47
created

UriParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 10
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isAbsolute() 0 4 1
A isMissingScheme() 0 4 2
A resolve() 0 4 1
A toPsrUri() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Risan\OAuth1\Request;
4
5
use GuzzleHttp\Psr7\Uri;
6
use InvalidArgumentException;
7
use GuzzleHttp\Psr7\UriResolver;
8
use Psr\Http\Message\UriInterface;
9
10
class UriParser implements UriParserInterface
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15 16
    public function isAbsolute(UriInterface $uri)
16
    {
17 16
        return Uri::isAbsolute($uri);
18
    }
19
20
    /**
21
     * {@inheritDoc}
22
     */
23 8
    public function isMissingScheme(UriInterface $uri)
24
    {
25 8
        return $uri->getScheme() === '' && $uri->getHost() !== '';
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31 7
    public function resolve(UriInterface $baseUri, UriInterface $uri)
32
    {
33 7
        return UriResolver::resolve($baseUri, $uri);
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 22 View Code Duplication
    public function toPsrUri($uri)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41 22
        if ($uri instanceof UriInterface) {
42 7
            return $uri;
43 22
        } elseif (is_string($uri)) {
44 21
            return new Uri($uri);
45
        }
46
47 1
        throw new InvalidArgumentException('URI must be a string or an instance of \Psr\Http\Message\UriInterface.');
48
    }
49
}
50