GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 423fe8...f48289 )
by gyeong-won
15:56 queued 08:14
created

session::serializeSession()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  session
5
 * @author NAVER ([email protected])
6
 * @brief session module's high class
7
 * @version 0.1
8
 *
9
 * The session management class
10
 */
11
class session extends ModuleObject
12
{
13
	var $lifetime = 18000;
14
	var $session_started = false;
15
16
	function session()
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
17
	{
18
		if(Context::isInstalled()) $this->session_started= true;
19
	}
20
21
	/**
22
	 * @brief Additional tasks required to accomplish during the installation
23
	 */
24
	function moduleInstall()
25
	{
26
		$oDB = &DB::getInstance();
27
		$oDB->addIndex("session","idx_session_update_mid", array("member_srl","last_update","cur_mid"));
28
29
		return new Object();
30
	}
31
32
	/**
33
	 * @brief A method to check if the installation has been successful
34
	 */
35 View Code Duplication
	function checkUpdate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
	{
37
		$oDB = &DB::getInstance();
38
		$oModuleModel = getModel('module');
39
		$oModuleController = getController('module');
40
		$version_update_id = implode('.', array(__CLASS__, __XE_VERSION__, 'updated'));
41
		if($oModuleModel->needUpdate($version_update_id))
42
		{
43
			if(!$oDB->isTableExists('session')) return true;
44
			if(!$oDB->isColumnExists("session","cur_mid")) return true;
45
			if(!$oDB->isIndexExists("session","idx_session_update_mid")) return true;
46
47
			$oModuleController->insertUpdatedLog($version_update_id);
48
		}
49
50
		return false;
51
	}
52
53
	/**
54
	 * @brief Execute update
55
	 */
56
	function moduleUpdate()
57
	{
58
		$oDB = &DB::getInstance();
59
		$oModuleModel = getModel('module');
60
		$oModuleController = getController('module');
61
		$version_update_id = implode('.', array(__CLASS__, __XE_VERSION__, 'updated'));
62
		if($oModuleModel->needUpdate($version_update_id))
63
		{
64
			if(!$oDB->isTableExists('session'))
65
			{
66
				$oDB->createTableByXmlFile($this->module_path.'schemas/session.xml');
0 ignored issues
show
Bug introduced by
The method createTableByXmlFile() does not exist on DB. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
67
			}
68
			if(!$oDB->isColumnExists("session","cur_mid"))
69
			{
70
				$oDB->addColumn('session',"cur_mid","varchar",128);
71
			}
72
			if(!$oDB->isIndexExists("session","idx_session_update_mid"))
73
			{
74
				$oDB->addIndex("session","idx_session_update_mid", array("member_srl","last_update","cur_mid"));
75
			}
76
77
			$oModuleController->insertUpdatedLog($version_update_id);
78
		}
79
80
		return new Object(0, 'success_updated');
81
	}
82
83
	/**
84
	 * @brief session string decode
85
	 */
86
	function unSerializeSession($val)
87
	{
88
		$vars = preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff^|]*)\|/', $val,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
89
		for($i=0; $vars[$i]; $i++) $result[$vars[$i++]] = unserialize($vars[$i]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
90
		return $result;
0 ignored issues
show
Bug introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
91
	}
92
93
	/**
94
	 * @brief session string encode
95
	 */
96
	function serializeSession($data)
97
	{
98
		if(!count($data)) return;
99
100
		$str = '';
101
		foreach($data as $key => $val) $str .= $key.'|'.serialize($val);
102
		return substr($str, 0, strlen($str)-1).'}';
103
	}
104
105
	/**
106
	 * @brief Re-generate the cache file
107
	 */
108
	function recompileCache()
109
	{
110
	}
111
}
112
/* End of file session.class.php */
113
/* Location: ./modules/session/session.class.php */
114