Http   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A requestProtocol() 0 4 2
A isSecure() 0 7 4
A checkHttp() 0 7 3
A checkHttpXforwardedProto() 0 7 3
A checkHttpXforwardedSsl() 0 7 3
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
     * Return https or http
28
     *
29
     * @return string
30
     */
31
    public function requestProtocol()
32
    {
33
        return $this->isSecure() ? 'https' : 'http';
34
    }
35
36
    /**
37
     * Check if the website is secure
38
     *
39
     * @return bool
40
     */
41
    private function isSecure()
42
    {
43
        if ($this->checkHttp() || $this->checkHttpXforwardedProto() || $this->checkHttpXforwardedSsl()) {
44
            return true;
45
        }
46
        return false;
47
    }
48
49
    /**
50
     * Check if HTTPS is 'on'
51
     *
52
     * @return bool
53
     */
54
    private function checkHttp()
55
    {
56
        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
57
            return true;
58
        }
59
        return false;
60
    }
61
62
    /**
63
     * Check if HTTP_X_FORWARDED_PROTO is not empty or 'https'
64
     *
65
     * @return bool
66
     */
67
    private function checkHttpXforwardedProto()
68
    {
69
        if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
70
            return true;
71
        }
72
        return false;
73
    }
74
75
    /**
76
     * Check if HTTP_X_FORWARDED_SSL is 'on'
77
     *
78
     * @return bool
79
     */
80
    private function checkHttpXforwardedSsl()
81
    {
82
        if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
83
            return true;
84
        }
85
        return false;
86
    }
87
}
88