Issues (105)

src/RequestContext/Traits/HasUrlFunctionsTrait.php (7 issues)

Labels
Severity
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
It seems like getBaseUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        return rtrim($this->getSchemeAndHttpHost() . $this->/** @scrutinizer ignore-call */ getBaseUrl(), '/');
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
It seems like getQueryString() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $query = $this->getQueryString();
Loading history...
31
        $question = $this->getBaseUrl() . $this->getPathInfo() == '/' ? '/?' : '?';
0 ignored issues
show
It seems like getPathInfo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        $question = $this->getBaseUrl() . $this->/** @scrutinizer ignore-call */ getPathInfo() == '/' ? '/?' : '?';
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()) {
55
            $queryString = '?' . $queryString;
56
        }
57
58
        return $this->getSchemeAndHttpHost() . $this->getBaseUrl() . $this->getPathInfo() . $queryString;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getSchemeAndHttpHost()
65
    {
66
        return $this->getScheme() . '://' . $this->getHttpHost();
0 ignored issues
show
The method getScheme() does not exist on Nip\Router\RequestContex...ts\HasUrlFunctionsTrait. Did you maybe mean getSchemeAndHttpHost()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        return $this->/** @scrutinizer ignore-call */ getScheme() . '://' . $this->getHttpHost();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getHttpHost()
73
    {
74
        $scheme = $this->getScheme();
75
        $port = '';
76
        if ('http' === $scheme && 80 != $this->getHttpPort()) {
0 ignored issues
show
The method getHttpPort() does not exist on Nip\Router\RequestContex...ts\HasUrlFunctionsTrait. Did you maybe mean getHttpHost()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        if ('http' === $scheme && 80 != $this->/** @scrutinizer ignore-call */ getHttpPort()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
            $port = ':' . $this->getHttpPort();
78
        } elseif ('https' === $scheme && 443 != $this->getHttpsPort()) {
0 ignored issues
show
The method getHttpsPort() does not exist on Nip\Router\RequestContex...ts\HasUrlFunctionsTrait. Did you maybe mean getHttpHost()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
        } elseif ('https' === $scheme && 443 != $this->/** @scrutinizer ignore-call */ getHttpsPort()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
        return $this->/** @scrutinizer ignore-call */ getHost() . $port;
Loading history...
83
    }
84
}
85