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 — develop ( c0df7f...390393 )
by gyeong-won
08:35
created

fileModel::getFiles()   C

Complexity

Conditions 14
Paths 25

Size

Total Lines 57
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 32
nc 25
nop 4
dl 0
loc 57
rs 6.5728
c 0
b 0
f 0

How to fix   Long Method    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
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * Model class of the file module
5
 * @author NAVER ([email protected])
6
 */
7
class fileModel extends file
8
{
9
	/**
10
	 * Initialization
11
	 * @return void
12
	 */
13
	function init()
14
	{
15
	}
16
17
	/**
18
	 * Return a file list attached in the document
19
	 *
20
	 * It is used when a file list of the upload_target_srl is requested for creating/updating a document.
21
	 * Attempt to replace with sever-side session if upload_target_srl is not yet determined
22
	 *
23
	 * @return void
24
	 */
25
	function getFileList()
26
	{
27
		$oModuleModel = getModel('module');
0 ignored issues
show
Unused Code introduced by
$oModuleModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
29
		$mid = Context::get('mid');
0 ignored issues
show
Unused Code introduced by
$mid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
		$editor_sequence = Context::get('editor_sequence');
31
		$upload_target_srl = Context::get('upload_target_srl');
32
		if(!$upload_target_srl) $upload_target_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl;
33
34
		if($upload_target_srl)
35
		{
36
			$tmp_files = $this->getFiles($upload_target_srl);
37
			if($tmp_files instanceof Object && !$tmp_files->toBool()) return $tmp_files;
38
39
			foreach($tmp_files as $file_info)
40
			{
41
				if(!$file_info->file_srl) continue;
42
43
				$obj = new stdClass;
44
				$obj->file_srl = $file_info->file_srl;
45
				$obj->source_filename = $file_info->source_filename;
46
				$obj->file_size = $file_info->file_size;
47
				$obj->disp_file_size = FileHandler::filesize($file_info->file_size);
48
				if($file_info->direct_download=='N') $obj->download_url = $this->getDownloadUrl($file_info->file_srl, $file_info->sid, $file_info->module_srl);
49
				else $obj->download_url = str_replace('./', '', $file_info->uploaded_filename);
50
				$obj->direct_download = $file_info->direct_download;
51
				$obj->cover_image = ($file_info->cover_image === 'Y') ? true : false;
52
				$files[] = $obj;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$files was never initialized. Although not strictly required by PHP, it is generally a good practice to add $files = 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...
53
				$attached_size += $file_info->file_size;
0 ignored issues
show
Bug introduced by
The variable $attached_size 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...
54
			}
55
		}
56
		else
57
		{
58
			$upload_target_srl = 0;
59
			$attached_size = 0;
60
			$files = array();
61
		}
62
		// Display upload status
63
		$upload_status = $this->getUploadStatus($attached_size);
64
		// Check remained file size until upload complete
65
		//$config = $oModuleModel->getModuleInfoByMid($mid);	//perhaps config varialbles not used
66
67
		$file_config = $this->getUploadConfig();
68
		$left_size = $file_config->allowed_attach_size*1024*1024 - $attached_size;
69
		// Settings of required information
70
		$attached_size = FileHandler::filesize($attached_size);
71
		$allowed_attach_size = FileHandler::filesize($file_config->allowed_attach_size*1024*1024);
72
		$allowed_filesize = FileHandler::filesize($file_config->allowed_filesize*1024*1024);
73
		$allowed_filetypes = $file_config->allowed_filetypes;
74
		$this->add("files",$files);
0 ignored issues
show
Bug introduced by
The variable $files 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...
75
		$this->add("editor_sequence",$editor_sequence);
76
		$this->add("upload_target_srl",$upload_target_srl);
77
		$this->add("upload_status",$upload_status);
78
		$this->add("left_size",$left_size);
79
		$this->add('attached_size', $attached_size);
80
		$this->add('allowed_attach_size', $allowed_attach_size);
81
		$this->add('allowed_filesize', $allowed_filesize);
82
		$this->add('allowed_filetypes', $allowed_filetypes);
83
	}
84
85
	/**
86
	 * Return number of attachments which belongs to a specific document
87
	 *
88
	 * @param int $upload_target_srl The sequence to get a number of files
89
	 * @return int Returns a number of files
90
	 */
91
	function getFilesCount($upload_target_srl)
92
	{
93
		$args = new stdClass();
94
		$args->upload_target_srl = $upload_target_srl;
95
		$output = executeQuery('file.getFilesCount', $args);
96
		return (int)$output->data->count;
97
	}
98
99
	/**
100
	 * Get a download path
101
	 *
102
	 * @param int $file_srl The sequence of file to get url
103
	 * @param string $sid
104
	 * @return string Returns a url
105
	 */
106
	function getDownloadUrl($file_srl, $sid, $module_srl="")
107
	{
108
		return sprintf('?module=%s&amp;act=%s&amp;file_srl=%s&amp;sid=%s&amp;module_srl=%s', 'file', 'procFileDownload', $file_srl, $sid, $module_srl);
109
	}
110
111
	/**
112
	 * Get file configurations
113
	 *
114
	 * @param int $module_srl If set this, returns specific module's configuration. Otherwise returns global configuration.
115
	 * @return object Returns configuration.
116
	 */
117
	function getFileConfig($module_srl = null)
118
	{
119
		// Get configurations (using module model object)
120
		$oModuleModel = getModel('module');
121
122
		$file_module_config = $oModuleModel->getModuleConfig('file');
123
124
		if($module_srl) $file_config = $oModuleModel->getModulePartConfig('file',$module_srl);
0 ignored issues
show
Bug Best Practice introduced by
The expression $module_srl of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
125
		if(!$file_config) $file_config = $file_module_config;
0 ignored issues
show
Bug introduced by
The variable $file_config 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...
126
127
		$config = new stdClass();
128
129
		if($file_config)
130
		{
131
			$config->allowed_filesize = $file_config->allowed_filesize;
132
			$config->allowed_attach_size = $file_config->allowed_attach_size;
133
			$config->allowed_filetypes = $file_config->allowed_filetypes;
134
			$config->download_grant = $file_config->download_grant;
135
			$config->allow_outlink = $file_config->allow_outlink;
136
			$config->allow_outlink_site = $file_config->allow_outlink_site;
137
			$config->allow_outlink_format = $file_config->allow_outlink_format;
138
		}
139
		// Property for all files comes first than each property
140
		if(!$config->allowed_filesize) $config->allowed_filesize = $file_module_config->allowed_filesize;
141
		if(!$config->allowed_attach_size) $config->allowed_attach_size = $file_module_config->allowed_attach_size;
142
		if(!$config->allowed_filetypes) $config->allowed_filetypes = $file_module_config->allowed_filetypes;
143
		if(!$config->allow_outlink) $config->allow_outlink = $file_module_config->allow_outlink;
144
		if(!$config->allow_outlink_site) $config->allow_outlink_site = $file_module_config->allow_outlink_site;
145
		if(!$config->allow_outlink_format) $config->allow_outlink_format = $file_module_config->allow_outlink_format;
146
		if(!$config->download_grant) $config->download_grant = $file_module_config->download_grant;
147
		// Default setting if not exists
148
		if(!$config->allowed_filesize) $config->allowed_filesize = '2';
149
		if(!$config->allowed_attach_size) $config->allowed_attach_size = '3';
150
		if(!$config->allowed_filetypes) $config->allowed_filetypes = '*.*';
151
		if(!$config->allow_outlink) $config->allow_outlink = 'Y';
152
		if(!$config->download_grant) $config->download_grant = array();
153
154
		$size = ini_get('upload_max_filesize');
155
		$unit = strtolower($size[strlen($size) - 1]);
156
		$size = (float)$size;
157
		if($unit == 'g') $size *= 1024;
158
		if($unit == 'k') $size /= 1024;
159
160
		if($config->allowed_filesize > $size) 
161
		{	
162
			$config->allowed_filesize = $size;
163
		}
164
		if($config->allowed_attach_size > $size) 
165
		{
166
			$config->allowed_attach_size = $size;
167
		}
168
		
169
		return $config;
170
	}
171
172
	/**
173
	 * Get file information
174
	 *
175
	 * @param int $file_srl The sequence of file to get information
176
	 * @param array $columnList The list of columns to get from DB
177
	 * @return Object|object|array If error returns an instance of Object. If result set is one returns a object that contins file information. If result set is more than one returns array of object.
178
	 */
179
	function getFile($file_srl, $columnList = array())
180
	{
181
		$args = new stdClass();
182
		$args->file_srl = $file_srl;
183
		$output = executeQueryArray('file.getFile', $args, $columnList);
184
		if(!$output->toBool()) return $output;
185
186
		// old version compatibility
187
		if(count($output->data) == 1)
188
		{
189
			$file = $output->data[0];
190
			$file->download_url = $this->getDownloadUrl($file->file_srl, $file->sid, $file->module_srl);
191
192
			return $file;
193
		}
194
		else
195
		{
196
			$fileList = array();
197
198
			if(is_array($output->data))
199
			{
200
				foreach($output->data as $key=>$value)
201
				{
202
					$file = $value;
203
					$file->download_url = $this->getDownloadUrl($file->file_srl, $file->sid, $file->module_srl);
204
					$fileList[] = $file;
205
				}
206
			}
207
			return $fileList;
208
		}
209
	}
210
211
	/**
212
	 * Return all files which belong to a specific document
213
	 *
214
	 * @param int $upload_target_srl The sequence of target to get file list
215
	 * @param array $columnList The list of columns to get from DB
216
	 * @param string $sortIndex The column that used as sort index
217
	 * @return array Returns array of object that contains file information. If no result returns null.
218
	 */
219
	function getFiles($upload_target_srl, $columnList = array(), $sortIndex = 'file_srl', $ckValid = false)
220
	{
221
		$oModuleModel = getModel('module');
222
		$oDocumentModel = getModel('document');
223
		$oCommentModel = getModel('comment');
224
		$logged_info = Context::get('logged_info');
225
226
		$oDocument = $oDocumentModel->getDocument($upload_target_srl);
227
228
		// comment 권한 확인
229
		if(!$oDocument->isExists())
230
		{
231
			$oComment = $oCommentModel->getComment($upload_target_srl);
232
			if($oComment->isExists() && $oComment->isSecret() && !$oComment->isGranted())
233
			{
234
				return $this->stop('msg_not_permitted');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->stop('msg_not_permitted'); (ModuleObject) is incompatible with the return type documented by fileModel::getFiles of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
235
			}
236
237
			$oDocument = $oDocumentModel->getDocument($oComment->get('document_srl'));
238
		}
239
240
		// document 권한 확인
241
		if($oDocument->isExists() && $oDocument->isSecret() && !$oDocument->isGranted())
242
		{
243
			return $this->stop('msg_not_permitted');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->stop('msg_not_permitted'); (ModuleObject) is incompatible with the return type documented by fileModel::getFiles of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
244
		}
245
246
		// 모듈 권한 확인
247
		$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($oDocument->get('module_srl')), $logged_info);
248
		if(!$grant->access)
249
		{
250
			return $this->stop('msg_not_permitted');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->stop('msg_not_permitted'); (ModuleObject) is incompatible with the return type documented by fileModel::getFiles of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
251
		}
252
253
		$args = new stdClass();
254
		$args->upload_target_srl = $upload_target_srl;
255
		$args->sort_index = $sortIndex;
256
		if($ckValid) $args->isvalid = 'Y';
257
		$output = executeQuery('file.getFiles', $args, $columnList);
258
		if(!$output->data) return;
259
260
		$file_list = $output->data;
261
262
		if($file_list && !is_array($file_list)) $file_list = array($file_list);
263
264
		$file_count = count($file_list);
265
		for($i=0;$i<$file_count;$i++)
266
		{
267
			$file = $file_list[$i];
268
			$file->source_filename = stripslashes($file->source_filename);
269
			$file->source_filename = htmlspecialchars($file->source_filename);
270
			$file->download_url = $this->getDownloadUrl($file->file_srl, $file->sid, $file->module_srl);
271
			$file_list[$i] = $file;
272
		}
273
274
		return $file_list;
275
	}
276
277
	/**
278
	 * Return configurations of the attachement (it automatically checks if an administrator is)
279
	 *
280
	 * @return object Returns a file configuration of current module. If user is admin, returns PHP's max file size and allow all file types.
281
	 */
282
	function getUploadConfig()
283
	{
284
		$logged_info = Context::get('logged_info');
285
286
		$module_srl = Context::get('module_srl');
287
		// Get the current module if module_srl doesn't exist
288
		if(!$module_srl)
289
		{
290
			$current_module_info = Context::get('current_module_info');
291
			$module_srl = $current_module_info->module_srl;
292
		}
293
		$file_config = $this->getFileConfig($module_srl);
294
295
		if($logged_info->is_admin == 'Y')
296
		{
297
			$iniPostMaxSize = FileHandler::returnbytes(ini_get('post_max_size'));
298
			$iniUploadMaxSize = FileHandler::returnbytes(ini_get('upload_max_filesize'));
299
			$size = min($iniPostMaxSize, $iniUploadMaxSize) / 1048576;
300
			$file_config->allowed_attach_size = $size;
301
			$file_config->allowed_filesize = $size;
302
			$file_config->allowed_filetypes = '*.*';
303
		}
304
		return $file_config;
305
	}
306
307
	/**
308
	 * Return messages for file upload and it depends whether an admin is or not
309
	 *
310
	 * @param int $attached_size
311
	 * @return string
312
	 */
313
	function getUploadStatus($attached_size = 0)
314
	{
315
		$file_config = $this->getUploadConfig();
316
		// Display upload status
317
		$upload_status = sprintf(
318
			'%s : %s/ %s<br /> %s : %s (%s : %s)',
319
			Context::getLang('allowed_attach_size'),
320
			FileHandler::filesize($attached_size),
321
			FileHandler::filesize($file_config->allowed_attach_size*1024*1024),
322
			Context::getLang('allowed_filesize'),
323
			FileHandler::filesize($file_config->allowed_filesize*1024*1024),
324
			Context::getLang('allowed_filetypes'),
325
			$file_config->allowed_filetypes
326
		);
327
		return $upload_status;
328
	}
329
330
	/**
331
	 * Return file configuration of the module
332
	 *
333
	 * @param int $module_srl The sequence of module to get configuration
334
	 * @return object
335
	 */
336
	function getFileModuleConfig($module_srl)
337
	{
338
		return $this->getFileConfig($module_srl);
339
	}
340
341
	/**
342
	 * Returns a grant of file
343
	 *
344
	 * @param object $file_info The file information to get grant
345
	 * @param object $member_info The member information to get grant
346
	 * @return object Returns a grant of file
347
	 */
348
	function getFileGrant($file_info, $member_info)
349
	{
350
		if(!$file_info) return null;
351
352
		if($_SESSION['__XE_UPLOADING_FILES_INFO__'][$file_info->file_srl])
353
		{
354
			$file_grant->is_deletable = true;
0 ignored issues
show
Bug introduced by
The variable $file_grant does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
355
			return $file_grant;
356
		}
357
358
		$oModuleModel = getModel('module');
359
		$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($file_info->module_srl), $member_info);
360
361
		$oDocumentModel = getModel('document');
362
		$oDocument = $oDocumentModel->getDocument($file_info->upload_target_srl);
363
		if($oDocument->isExists()) $document_grant = $oDocument->isGranted();
364
365
		$file_grant->is_deletable = ($document_grant || $member_info->is_admin == 'Y' || $member_info->member_srl == $file_info->member_srl || $grant->manager);
0 ignored issues
show
Bug introduced by
The variable $document_grant 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...
366
367
		return $file_grant;
368
	}
369
}
370
/* End of file file.model.php */
371
/* Location: ./modules/file/file.model.php */
372