StartAfter::execute()   F
last analyzed

Complexity

Conditions 13
Paths 250

Size

Total Lines 47
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 22
nc 250
nop 0
dl 0
loc 47
rs 3.7737
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
  * osCommerce Online Merchant
4
  *
5
  * @copyright (c) 2016 osCommerce; https://www.oscommerce.com
6
  * @license MIT; https://www.oscommerce.com/license/mit.txt
7
  */
8
9
namespace OSC\OM\Module\Hooks\Shop\Session;
10
11
use OSC\OM\Hash;
12
use OSC\OM\HTTP;
13
use OSC\OM\OSCOM;
14
use OSC\OM\Registry;
15
16
class StartAfter
17
{
18
    public function execute() {
19
        $OSCOM_Session = Registry::get('Session');
20
21
// initialize a session token
22
        if (!isset($_SESSION['sessiontoken'])) {
23
            $_SESSION['sessiontoken'] = md5(Hash::getRandomInt() . Hash::getRandomInt() . Hash::getRandomInt() . Hash::getRandomInt());
24
        }
25
26
// verify the ssl_session_id if the feature is enabled
27
        if ((HTTP::getRequestType() === 'SSL') && (SESSION_CHECK_SSL_SESSION_ID == 'True') && $OSCOM_Session->hasStarted()) {
28
            if (!isset($_SESSION['SSL_SESSION_ID'])) {
29
                $_SESSION['SESSION_SSL_ID'] = $_SERVER['SSL_SESSION_ID'];
30
            }
31
32
            if ($_SESSION['SESSION_SSL_ID'] != $_SERVER['SSL_SESSION_ID']) {
33
                $OSCOM_Session->kill();
34
35
                OSCOM::redirect('ssl_check.php');
36
            }
37
        }
38
39
// verify the browser user agent if the feature is enabled
40
        if (SESSION_CHECK_USER_AGENT == 'True') {
41
            if (!isset($_SESSION['SESSION_USER_AGENT'])) {
42
                $_SESSION['SESSION_USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
43
            }
44
45
            if ($_SESSION['SESSION_USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) {
46
                $OSCOM_Session->kill();
47
48
                OSCOM::redirect('login.php');
49
            }
50
        }
51
52
// verify the IP address if the feature is enabled
53
        if (SESSION_CHECK_IP_ADDRESS == 'True') {
54
            if (!isset($_SESSION['SESSION_IP_ADDRESS'])) {
55
                $_SESSION['SESSION_IP_ADDRESS'] = HTTP::getIpAddress();
56
            }
57
58
            if ($_SESSION['SESSION_IP_ADDRESS'] != HTTP::getIpAddress()) {
59
                $OSCOM_Session->kill();
60
61
                OSCOM::redirect('login.php');
62
            }
63
        }
64
    }
65
}
66