bytic /
controllers
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Nip\Controllers\Traits; |
||||||
| 4 | |||||||
| 5 | use Nip\Http\Request; |
||||||
| 6 | |||||||
| 7 | /** |
||||||
| 8 | * Trait HttpsTrait |
||||||
| 9 | * @package Nip\Controllers\Traits |
||||||
| 10 | */ |
||||||
| 11 | trait HttpsTrait |
||||||
| 12 | { |
||||||
| 13 | /** |
||||||
| 14 | * @param Request|null $request |
||||||
| 15 | */ |
||||||
| 16 | public function checkSecureRequest(Request $request = null) |
||||||
| 17 | { |
||||||
| 18 | if ($this->needsSecureRequest($request)) { |
||||||
| 19 | $this->forceSecureRequest($request); |
||||||
| 20 | } |
||||||
| 21 | } |
||||||
| 22 | |||||||
| 23 | /** |
||||||
| 24 | * @param Request|null $request |
||||||
| 25 | */ |
||||||
| 26 | public function forceSecureRequest(Request $request = null) |
||||||
| 27 | { |
||||||
| 28 | $request = $request ? $request : $this->getRequest(); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 29 | if ($this->isSecureRequest($request)) { |
||||||
| 30 | return; |
||||||
| 31 | } |
||||||
| 32 | $this->redirect(str_replace('http://', 'https://', $request->fullUrl())); |
||||||
|
0 ignored issues
–
show
It seems like
redirect() 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
Loading history...
|
|||||||
| 33 | } |
||||||
| 34 | |||||||
| 35 | /** |
||||||
| 36 | * @param Request $request |
||||||
| 37 | * @return mixed |
||||||
| 38 | */ |
||||||
| 39 | public function isSecureRequest(Request $request = null) |
||||||
| 40 | { |
||||||
| 41 | $request = $request ? $request : $this->getRequest(); |
||||||
| 42 | |||||||
| 43 | return $request->isSecure(); |
||||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | /** |
||||||
| 47 | * @param Request|null $request |
||||||
| 48 | * @return bool |
||||||
| 49 | */ |
||||||
| 50 | protected function needsSecureRequest(Request $request = null) |
||||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 51 | { |
||||||
| 52 | return false; |
||||||
| 53 | } |
||||||
| 54 | } |
||||||
| 55 |