Passed
Branch master (b52c46)
by refat
04:18
created

Http::checkHttp()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace System\Http;
4
5
use System\Application;
6
7
class Http
8
{
9
    /**
10
     * Application Object
11
     *
12
     * @var \System\Application
13
     */
14
    private $app;
15
16
    /**
17
     * Constructor
18
     *
19
     * @param \System\Application $app
20
     */
21
    public function __construct(Application $app)
22
    {
23
        $this->app = $app;
24
    }
25
26
        /**
27
     * Check if the website is secure
28
     *
29
     * @return bool
30
     */
31
    public function isSecure()
32
    {
33
        if ($this->checkHttp() || $this->checkHttpXforwardedProto() || $this->checkHttpXforwardedSsl()) {
34
            return true;
35
        }
36
        return false;
37
    }
38
39
    /**
40
     * Check if HTTPS is 'on'
41
     *
42
     * @return bool
43
     */
44
    private function checkHttp()
45
    {
46
        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
47
            return true;
48
        }
49
        return false;
50
    }
51
52
    /**
53
     * Check if HTTP_X_FORWARDED_PROTO is not empty or 'https'
54
     *
55
     * @return bool
56
     */
57
    private function checkHttpXforwardedProto()
58
    {
59
        if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
60
            return true;
61
        }
62
        return false;
63
    }
64
65
    /**
66
     * Check if HTTP_X_FORWARDED_SSL is 'on'
67
     *
68
     * @return bool
69
     */
70
    private function checkHttpXforwardedSsl()
71
    {
72
        if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
73
            return true;
74
        }
75
        return false;
76
    }
77
}
78