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
![]() |
|||||||
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
![]() |
|||||||
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
![]() |
|||||||
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
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. ![]() |
|||||||
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
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. ![]() |
|||||||
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
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. ![]() |
|||||||
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
![]() |
|||||||
83 | } |
||||||
84 | } |
||||||
85 |