Test Setup Failed
Push — master ( 423952...415317 )
by Gabriel
02:26 queued 10s
created

HasUrlFunctionsTrait::getUri()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Router\RequestContext\Traits;
4
5
/**
6
 * Trait HasUrlFunctionsTrait
7
 * @package Nip\Router\RequestContext\Traits
8
 */
9
trait HasUrlFunctionsTrait
10
{
11
12
    /**
13
     * Get the root URL for the application.
14
     *
15
     * @return string
16
     */
17
    public function root()
18
    {
19
        return rtrim($this->getSchemeAndHttpHost() . $this->getBaseUrl(), '/');
0 ignored issues
show
Bug introduced by
It seems like getBaseUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
20
    }
21
22
23
    /**
24
     * Get the full URL for the request.
25
     *
26
     * @return string
27
     */
28
    public function fullUrl()
29
    {
30
        $query = $this->getQueryString();
0 ignored issues
show
Bug introduced by
It seems like getQueryString() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31
        $question = $this->getBaseUrl() . $this->getPathInfo() == '/' ? '/?' : '?';
0 ignored issues
show
Bug introduced by
It seems like getBaseUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like getPathInfo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
        return $query ? $this->url() . $question . $query : $this->url();
33
    }
34
35
    /**
36
     * Get the URL (no query string) for the request.
37
     *
38
     * @return string
39
     */
40
    public function url()
41
    {
42
        return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');
43
    }
44
45
    /**
46
     * Generates a normalized URI (URL) for the Request.
47
     *
48
     * @return string A normalized URI (URL) for the Request
49
     *
50
     * @see getQueryString()
51
     */
52
    public function getUri()
53
    {
54
        if (null !== $queryString = $this->getQueryString()) {
0 ignored issues
show
Bug introduced by
It seems like getQueryString() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
55
            $queryString = '?' . $queryString;
56
        }
57
58
        return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $this->getPathInfo() . $queryString;
0 ignored issues
show
Bug introduced by
It seems like getBaseUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like getPathInfo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getSchemeAndHttpHost()
65
    {
66
        return $this->getScheme() . '://' . $this->getHttpHost();
0 ignored issues
show
Bug introduced by
The method getScheme() does not exist on Nip\Router\RequestContex...ts\HasUrlFunctionsTrait. Did you maybe mean getSchemeAndHttpHost()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getHttpHost()
73
    {
74
        $scheme = $this->getScheme();
0 ignored issues
show
Bug introduced by
The method getScheme() does not exist on Nip\Router\RequestContex...ts\HasUrlFunctionsTrait. Did you maybe mean getSchemeAndHttpHost()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
75
        $port = $this->getHttpPort();
0 ignored issues
show
Bug introduced by
It seems like getHttpPort() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
76
77
        if (('http' == $scheme && 80 == $port) || ('https' == $scheme && 443 == $port)) {
78
            return $this->getHost();
0 ignored issues
show
Bug introduced by
It seems like getHost() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
79
        }
80
81
        return $this->getHost() . ':' . $port;
0 ignored issues
show
Bug introduced by
It seems like getHost() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
82
    }
83
}