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
Pull Request — develop (#1929)
by
unknown
11:46
created

widgetModel::getWidgetStyleInfo()   F

Complexity

Conditions 25
Paths > 20000

Size

Total Lines 105
Code Lines 67

Duplication

Lines 7
Ratio 6.67 %

Importance

Changes 0
Metric Value
cc 25
eloc 67
nc 21124
nop 1
dl 7
loc 105
rs 2
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
 * @class  widgetModel
5
 * @author NAVER ([email protected])
6
 * @version 0.1
7
 * @brief Model class for widget modules
8
 */
9
class widgetModel extends widget
10
{
11
	/**
12
	 * @brief Initialization
13
	 */
14
	function init()
15
	{
16
	}
17
18
	/**
19
	 * @brief Wanted widget's path
20
	 */
21
	function getWidgetPath($widget_name)
22
	{
23
		$path = sprintf('./widgets/%s/', $widget_name);
24
		if(is_dir($path)) return $path;
25
26
		return "";
27
	}
28
29
	/**
30
	 * @brief Wanted widget style path
31
	 */
32
	function getWidgetStylePath($widgetStyle_name)
33
	{
34
		$path = sprintf('./widgetstyles/%s/', $widgetStyle_name);
35
		if(is_dir($path)) return $path;
36
37
		return "";
38
	}
39
40
	/**
41
	 * @brief Wanted widget style path
42
	 */
43
	function getWidgetStyleTpl($widgetStyle_name)
44
	{
45
		$path = $this->getWidgetStylePath($widgetStyle_name);
46
		$tpl = sprintf('%swidgetstyle.html', $path);
47
		return $tpl;
48
	}
49
50
	/**
51
	 * @brief Wanted photos of the type and information
52
	 * Download a widget with type (generation and other means)
53
	 */
54
	function getDownloadedWidgetList()
55
	{
56
		$oAutoinstallModel = getModel('autoinstall');
57
58
		// 've Downloaded the widget and the widget's list of installed Wanted
59
		$searched_list = FileHandler::readDir('./widgets');
60
		$searched_count = count($searched_list);
61
		if(!$searched_count) return;
62
		sort($searched_list);
63
		// D which pertain to the list of widgets loop spins return statement review the information you need
64 View Code Duplication
		for($i=0;$i<$searched_count;$i++)
65
		{
66
			// The name of the widget
67
			$widget = $searched_list[$i];
68
			// Wanted information on the Widget
69
			$widget_info = $this->getWidgetInfo($widget);
70
71
			if(!$widget_info)
72
			{
73
				$widget_info = new stdClass();
74
			}
75
76
			// get easyinstall remove url
77
			$packageSrl = $oAutoinstallModel->getPackageSrlByPath($widget_info->path);
78
			$widget_info->remove_url = $oAutoinstallModel->getRemoveUrlByPackageSrl($packageSrl);
79
80
			// get easyinstall need update
81
			$package = $oAutoinstallModel->getInstalledPackages($packageSrl);
82
			$widget_info->need_update = $package[$packageSrl]->need_update;
83
84
			// get easyinstall update url
85
			if ($widget_info->need_update == 'Y')
86
			{
87
				$widget_info->update_url = $oAutoinstallModel->getUpdateUrlByPackageSrl($packageSrl);
88
			}
89
90
			$list[] = $widget_info;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $list = 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...
91
		}
92
		return $list;
0 ignored issues
show
Bug introduced by
The variable $list 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...
93
	}
94
95
	/**
96
	 * @brief Wanted photos of the type and information
97
	 * Download a widget with type (generation and other means)
98
	 */
99
	function getDownloadedWidgetStyleList()
100
	{
101
		// 've Downloaded the widget and the widget's list of installed Wanted
102
		$searched_list = FileHandler::readDir('./widgetstyles');
103
		$searched_count = count($searched_list);
104
		if(!$searched_count) return;
105
		sort($searched_list);
106
		// D which pertain to the list of widgets loop spins return statement review the information you need
107
		for($i=0;$i<$searched_count;$i++)
108
		{
109
			// The name of the widget
110
			$widgetStyle = $searched_list[$i];
111
			// Wanted information on the Widget
112
			$widgetStyle_info = $this->getWidgetStyleInfo($widgetStyle);
113
114
			$list[] = $widgetStyle_info;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $list = 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...
115
		}
116
		return $list;
0 ignored issues
show
Bug introduced by
The variable $list 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...
117
	}
118
119
	/**
120
	 * @brief Modules conf/info.xml wanted to read the information
121
	 * It uses caching to reduce time for xml parsing ..
122
	 */
123
	function getWidgetInfo($widget)
124
	{
125
		// Get a path of the requested module. Return if not exists.
126
		$widget_path = $this->getWidgetPath($widget);
127
		if(!$widget_path) return;
128
		// Read the xml file for module skin information
129
		$xml_file = sprintf("%sconf/info.xml", $widget_path);
130
		if(!file_exists($xml_file)) return;
131
		// If the problem by comparing the cache file and include the return variable $widget_info
132
		$cache_file = sprintf(_XE_PATH_ . 'files/cache/widget/%s.%s.cache.php', $widget, Context::getLangType());
133
134 View Code Duplication
		if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
135
		{
136
			@include($cache_file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
137
			return $widget_info;
0 ignored issues
show
Bug introduced by
The variable $widget_info does not exist. Did you mean $widget?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
138
		}
139
		// If no cache file exists, parse the xml and then return the variable.
140
		$oXmlParser = new XmlParser();
141
		$tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
142
		$xml_obj = $tmp_xml_obj->widget;
143
		if(!$xml_obj) return;
144
145
		$buff = '$widget_info = new stdClass;';
146
147
		if($xml_obj->version && $xml_obj->attrs->version == '0.2')
148
		{
149
			// Title of the widget, version
150
			$buff .= sprintf('$widget_info->widget = "%s";', $widget);
151
			$buff .= sprintf('$widget_info->path = "%s";', $widget_path);
152
			$buff .= sprintf('$widget_info->title = "%s";', $xml_obj->title->body);
153
			$buff .= sprintf('$widget_info->description = "%s";', $xml_obj->description->body);
154
			$buff .= sprintf('$widget_info->version = "%s";', $xml_obj->version->body);
155
			sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
0 ignored issues
show
Bug introduced by
The variable $date_obj 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...
156
			$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
157
			$buff .= sprintf('$widget_info->date = "%s";', $date);
158
			$buff .= sprintf('$widget_info->homepage = "%s";', $xml_obj->link->body);
159
			$buff .= sprintf('$widget_info->license = "%s";', $xml_obj->license->body);
160
			$buff .= sprintf('$widget_info->license_link = "%s";', $xml_obj->license->attrs->link);
161
			$buff .= sprintf('$widget_info->widget_srl = $widget_srl;');
162
			$buff .= sprintf('$widget_info->widget_title = $widget_title;');
163
			// Author information
164 View Code Duplication
			if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$author_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $author_list = 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...
165
			else $author_list = $xml_obj->author;
166
167
			for($i=0; $i < count($author_list); $i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
168
			{
169
				$buff .= '$widget_info->author['.$i.'] = new stdClass;';
170
				$buff .= sprintf('$widget_info->author['.$i.']->name = "%s";', $author_list[$i]->name->body);
171
				$buff .= sprintf('$widget_info->author['.$i.']->email_address = "%s";', $author_list[$i]->attrs->email_address);
172
				$buff .= sprintf('$widget_info->author['.$i.']->homepage = "%s";', $author_list[$i]->attrs->link);
173
			}
174
		}
175
		else
176
		{
177
			// Title of the widget, version
178
			$buff .= sprintf('$widget_info->widget = "%s";', $widget);
179
			$buff .= sprintf('$widget_info->path = "%s";', $widget_path);
180
			$buff .= sprintf('$widget_info->title = "%s";', $xml_obj->title->body);
181
			$buff .= sprintf('$widget_info->description = "%s";', $xml_obj->author->description->body);
182
			$buff .= sprintf('$widget_info->version = "%s";', $xml_obj->attrs->version);
183
			sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
184
			$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
185
			$buff .= sprintf('$widget_info->date = "%s";', $date);
186
			$buff .= sprintf('$widget_info->widget_srl = $widget_srl;');
187
			$buff .= sprintf('$widget_info->widget_title = $widget_title;');
188
			// Author information
189
			$buff .= '$widget_info->author[0] = new stdClass;';
190
			$buff .= sprintf('$widget_info->author[0]->name = "%s";', $xml_obj->author->name->body);
191
			$buff .= sprintf('$widget_info->author[0]->email_address = "%s";', $xml_obj->author->attrs->email_address);
192
			$buff .= sprintf('$widget_info->author[0]->homepage = "%s";', $xml_obj->author->attrs->link);
193
		}
194
		// Extra vars (user defined variables to use in a template)
195
		$extra_var_groups = $xml_obj->extra_vars->group;
196
		if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
197
		if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
198
		foreach($extra_var_groups as $group)
199
		{
200
			$extra_vars = $group->var;
201
			if(!is_array($group->var)) $extra_vars = array($group->var);
202
203
			if($extra_vars[0]->attrs->id || $extra_vars[0]->attrs->name)
204
			{
205
				$extra_var_count = count($extra_vars);
206
207
				$buff .= sprintf('$widget_info->extra_var_count = "%s";', $extra_var_count);
208
				for($i=0;$i<$extra_var_count;$i++)
209
				{
210
					unset($var);
211
					unset($options);
212
					$var = $extra_vars[$i];
213
214
					$id = $var->attrs->id?$var->attrs->id:$var->attrs->name;
215
					$name = $var->name->body?$var->name->body:$var->title->body;
216
					$type = $var->attrs->type?$var->attrs->type:$var->type->body;
217
					$buff .= sprintf('$widget_info->extra_var->%s = new stdClass;', $id);
218
					if($type =='filebox')
219
					{
220
						$buff .= sprintf('$widget_info->extra_var->%s->filter = "%s";', $id, $var->type->attrs->filter);
221
						$buff .= sprintf('$widget_info->extra_var->%s->allow_multiple = "%s";', $id, $var->type->attrs->allow_multiple);
222
					}
223
224
					$buff .= sprintf('$widget_info->extra_var->%s->group = "%s";', $id, $group->title->body);
225
					$buff .= sprintf('$widget_info->extra_var->%s->name = "%s";', $id, $name);
226
					$buff .= sprintf('$widget_info->extra_var->%s->type = "%s";', $id, $type);
227
					$buff .= sprintf('$widget_info->extra_var->%s->value = $vars->%s;', $id, $id);
228
					$buff .= sprintf('$widget_info->extra_var->%s->description = "%s";', $id, str_replace('"','\"',$var->description->body));
229
230
					$options = $var->options;
231
					if(!$options) continue;
232
233
					if(!is_array($options)) $options = array($options);
234
					$options_count = count($options);
235
					for($j=0;$j<$options_count;$j++)
236
					{
237
						$buff .= sprintf('$widget_info->extra_var->%s->options["%s"] = "%s";', $id, $options[$j]->value->body, $options[$j]->name->body);
238
239 View Code Duplication
						if($options[$j]->attrs->default && $options[$j]->attrs->default=='true')
240
						{
241
							$buff .= sprintf('$widget_info->extra_var->%s->default_options["%s"] = true;', $id, $options[$j]->value->body);
242
						}
243
244 View Code Duplication
						if($options[$j]->attrs->init && $options[$j]->attrs->init=='true')
245
						{
246
							$buff .= sprintf('$widget_info->extra_var->%s->init_options["%s"] = true;', $id, $options[$j]->value->body);
247
						}
248
					}
249
				}
250
			}
251
		}
252
253
		$buff = '<?php if(!defined("__XE__")) exit(); '.$buff.' ?>';
254
		FileHandler::writeFile($cache_file, $buff);
255
256
		if(file_exists($cache_file)) @include($cache_file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
257
		return $widget_info;
0 ignored issues
show
Bug introduced by
The variable $widget_info does not exist. Did you mean $widget?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
258
	}
259
260
	/**
261
	 * @brief Modules conf/info.xml wanted to read the information
262
	 * It uses caching to reduce time for xml parsing ..
263
	 */
264
	function getWidgetStyleInfo($widgetStyle)
265
	{
266
		$widgetStyle_path = $this->getWidgetStylePath($widgetStyle);
267
		if(!$widgetStyle_path) return;
268
		$xml_file = sprintf("%sskin.xml", $widgetStyle_path);
269
		if(!file_exists($xml_file)) return;
270
		// If the problem by comparing the cache file and include the return variable $widgetStyle_info
271
		$cache_file = sprintf(_XE_PATH_ . 'files/cache/widgetstyles/%s.%s.cache.php', $widgetStyle, Context::getLangType());
272
273 View Code Duplication
		if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
274
		{
275
			@include($cache_file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
276
			return $widgetStyle_info;
0 ignored issues
show
Bug introduced by
The variable $widgetStyle_info does not exist. Did you mean $widgetStyle?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
277
		}
278
		// If no cache file exists, parse the xml and then return the variable.
279
		$oXmlParser = new XmlParser();
280
		$tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
281
		$xml_obj = $tmp_xml_obj->widgetstyle;
282
		if(!$xml_obj) return;
283
284
		$buff = array();
285
		$buff[] = '<?php if(!defined("__XE__")) exit();';
286
		$buff[] = '$widgetStyle_info = new stdClass();';
287
288
		// Title of the widget, version
289
		$buff[] = sprintf('$widgetStyle_info->widgetStyle = "%s";', $widgetStyle);
290
		$buff[] = sprintf('$widgetStyle_info->path = "%s";', $widgetStyle_path);
291
		$buff[] = sprintf('$widgetStyle_info->title = "%s";', $xml_obj->title->body);
292
		$buff[] = sprintf('$widgetStyle_info->description = "%s";', $xml_obj->description->body);
293
		$buff[] = sprintf('$widgetStyle_info->version = "%s";', $xml_obj->version->body);
294
		sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
0 ignored issues
show
Bug introduced by
The variable $date_obj 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...
295
		$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
296
		$buff[] = sprintf('$widgetStyle_info->date = "%s";', $date);
297
		$buff[] = sprintf('$widgetStyle_info->homepage = "%s";', $xml_obj->link->body);
298
		$buff[] = sprintf('$widgetStyle_info->license = "%s";', $xml_obj->license->body);
299
		$buff[] = sprintf('$widgetStyle_info->license_link = "%s";', $xml_obj->license->attrs->link);
300
301
		// preview
302
		if(!$xml_obj->preview->body) $xml_obj->preview->body = 'preview.jpg';
303
		$preview_file = sprintf("%s%s", $widgetStyle_path,$xml_obj->preview->body);
304
		if(file_exists($preview_file)) $buff[] = sprintf('$widgetStyle_info->preview = "%s";', $preview_file);
305
306
		// Author information
307 View Code Duplication
		if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$author_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $author_list = 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...
308
		else $author_list = $xml_obj->author;
309
310
		foreach($author_list as $idx => $author)
311
		{
312
			$buff[] = sprintf('$widgetStyle_info->author[%d] = new stdClass();', $idx);
313
			$buff[] = sprintf('$widgetStyle_info->author[%d]->name = "%s";', $idx, $author->name->body);
314
			$buff[] = sprintf('$widgetStyle_info->author[%d]->email_address = "%s";', $idx, $author->attrs->email_address);
315
			$buff[] = sprintf('$widgetStyle_info->author[%d]->homepage = "%s";', $idx, $author->attrs->link);
316
		}
317
318
		// Extra vars (user defined variables to use in a template)
319
		$extra_var_groups = $xml_obj->extra_vars->group;
320
		if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
321
		if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
322
323
		$extra_var_count = 0;
324
		$buff[] = sprintf('$widgetStyle_info->extra_var = new stdClass();', $extra_var_count);
325
		foreach($extra_var_groups as $group)
326
		{
327
			$extra_vars = (!is_array($group->var)) ? array($group->var) : $group->var;
328
329
			if($extra_vars[0]->attrs->id || $extra_vars[0]->attrs->name)
330
			{
331
				foreach($extra_vars as $var)
332
				{
333
					$extra_var_count++;
334
					$id = ($var->attrs->id) ? $var->attrs->id : $var->attrs->name;
335
					$name = ($var->name->body) ? $var->name->body : $var->title->body;
336
					$type = ($var->attrs->type) ? $var->attrs->type : $var->type->body;
337
338
					$buff[] = sprintf('$widgetStyle_info->extra_var->%s = new stdClass();', $id);
339
					$buff[] = sprintf('$widgetStyle_info->extra_var->%s->group = "%s";', $id, $group->title->body);
340
					$buff[] = sprintf('$widgetStyle_info->extra_var->%s->name = "%s";', $id, $name);
341
					$buff[] = sprintf('$widgetStyle_info->extra_var->%s->type = "%s";', $id, $type);
342
					if($type =='filebox')
343
					{
344
						$buff[] = sprintf('$widgetStyle_info->extra_var->%s->filter = "%s";', $id, $var->attrs->filter);
345
						$buff[] = sprintf('$widgetStyle_info->extra_var->%s->allow_multiple = "%s";', $id, $var->attrs->allow_multiple);
346
					}
347
					$buff[] = sprintf('$widgetStyle_info->extra_var->%s->value = $vars->%s;', $id, $id);
348
					$buff[] = sprintf('$widgetStyle_info->extra_var->%s->description = "%s";', $id, str_replace('"','\"',$var->description->body));
349
350
					if($var->options)
351
					{
352
						$var_options = (!is_array($var->options)) ? array($var->options) : $var->options;
353
						foreach($var_options as $option_item)
354
						{
355
							$buff[] = sprintf('$widgetStyle_info->extra_var->%s->options["%s"] = "%s";', $id, $option_item->value->body, $option_item->name->body);
356
						}
357
					}
358
				}
359
			}
360
		}
361
		$buff[] = sprintf('$widgetStyle_info->extra_var_count = %d;', $extra_var_count);
362
363
		FileHandler::writeFile($cache_file, implode(PHP_EOL, $buff));
364
365
		if(file_exists($cache_file)) @include($cache_file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
366
367
		return $widgetStyle_info;
0 ignored issues
show
Bug introduced by
The variable $widgetStyle_info does not exist. Did you mean $widgetStyle?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
368
	}
369
}
370
/* End of file widget.model.php */
371
/* Location: ./modules/widget/widget.model.php */
372