HttpsTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 10
c 1
b 0
f 1
dl 0
loc 42
ccs 0
cts 15
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A forceSecureRequest() 0 7 3
A checkSecureRequest() 0 4 2
A needsSecureRequest() 0 3 1
A isSecureRequest() 0 5 2
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
It seems like getRequest() 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

28
        $request = $request ? $request : $this->/** @scrutinizer ignore-call */ getRequest();
Loading history...
29
        if ($this->isSecureRequest($request)) {
30
            return;
31
        }
32
        $this->redirect(str_replace('http://', 'https://', $request->fullUrl()));
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

32
        $this->/** @scrutinizer ignore-call */ 
33
               redirect(str_replace('http://', 'https://', $request->fullUrl()));
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
Unused Code introduced by
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 ignore-unused  annotation

50
    protected function needsSecureRequest(/** @scrutinizer ignore-unused */ Request $request = null)

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