import_wddx   F
last analyzed

Complexity

Total Complexity 93

Size/Duplication

Total Lines 533
Duplicated Lines 10.51 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 56
loc 533
rs 2
c 0
b 0
f 0
ccs 0
cts 405
cp 0
wmc 93
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A print_verbose() 0 5 2
A __construct() 0 13 1
C startElement() 0 30 14
C endElement() 0 65 16
A saveObject() 0 31 5
A linkObject() 0 8 2
F storeObject() 56 323 44
B characterData() 0 22 6
A parse() 0 16 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like import_wddx often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use import_wddx, and based on these observations, apply Extract Interface, too.

1
<?php
2
class import_wddx {
3
4
	var $stack;
5
	var $nestdeep;
6
	var $input;
7
	var $xml_parser;
8
	var $store;
9
	var $config;
10
	var $linktable;
11
	var $seenconfig;
12
13
	function print_verbose($message){
14
		if($this->config['verbose']){
15
			print $message;
16
		}
17
	}
18
19
	function __construct($options){
20
		$this->input = null;
21
		$this->nestdeep = -4;
22
		$this->stack = array();
23
		$this->xml_parser = xml_parser_create();
24
		// use case-folding so we are sure to find the tag in $map_array
25
		xml_set_object($this->xml_parser, $this);
26
		xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false);
27
		xml_set_element_handler($this->xml_parser, "startElement", "endElement");
28
		xml_set_character_data_handler($this->xml_parser, "characterData");
29
		$this->config = $options;
30
		$this->linktable = array();
31
	}
32
33
	function startElement($parser, $name, $attribs) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
		$this->nestdeep++;
35
		switch($name) {
36
			case "wddxPacket":
37
			case "header":
38
			case "comment":
39
			case "version":
40
			case "data":
41
				array_push($this->stack, Array("type" => "top", "data" => array()));
42
				break;
43
			case "struct":
44
				if(($attribs["class"] == "object" || $attribs["class"] == "stdClass") && ($attribs["type"] == "object" ))
45
				{
46
					$value = new baseObject();
47
				} else
48
				{
49
					$value = Array();
50
				}
51
				array_push($this->stack, Array("type" => $attribs["type"], "data" => $value));
52
				break;
53
			case "var":
54
				array_push($this->stack, Array("type" => $name, "data" => $attribs["name"]));
55
				break;
56
			case "number":
57
			case "string":
58
			case "boolean":
59
				array_push($this->stack, Array("type" => $name));
60
				break;
61
		}
62
	}
63
64
	function endElement($parser, $name) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
		$this->nestdeep--;
66
67
		$element = &$this->stack[count($this->stack)-1];
68
		$element["locked"] = true;
69
70
		if($name == "var")
71
		{
72
			$value = array_pop($this->stack);
73
			if ($value["type"] == "var") {
74
				/* we did get a key without a value */
75
				$var = $value;
76
			} else {
77
				$var = array_pop($this->stack);
78
			}
79
			$struct = array_pop($this->stack);
80
81
			if ( is_string( $value['data'] ) && $this->seenconfig && ( $this->config['srcpath'] != $this->config['dstpath'] ) ) {
82
				$value['data'] = preg_replace( '#(^|[\'"])'.$this->config['srcpath'].'#i', '$1'.$this->config['dstpath'], $value['data'] );
83
			}
84
85
			$key = $var["data"];
86
			if(is_object($struct["data"]))
87
			{
88
				$struct["data"]->$key = $value["data"];
89
			} else if(is_array($struct["data"]))
90
			{
91
				$struct["data"][$key] = $value["data"];
92
			} else {
93
				echo "corrupted data found:\n";
94
				echo "#.#.#.#\n";
95
				print_r($struct["data"]);
96
				echo "#.#.#.#\n";
97
				print_r($this->stack);
98
				echo "#.#.#.#\n";
99
			}
100
101
			array_push($this->stack, $struct);
102
		} else if( $name == "struct"){
103
			if(!$this->seenconfig){
104
				// still waiting for the config
105
				if($this->nestdeep == -2){
106
					// -1 is the depth directly under <data>
107
					// -2 is the struct with the wddx configuration data
108
					$this->seenconfig = true;
109
					$config = (array_pop($this->stack));
110
					// oke do something with the config data please ?
111
					foreach ($config[data][options] as  $key => $value){
112
						if(!isset($this->config[$key])){
113
							$this->print_verbose("Taking config from wddx: $key => $value \n");
114
							$this->config[$key] = $value;
115
						}
116
					}
117
				}
118
			} else {
119
				if($this->nestdeep == 0 ){ // this is below
120
					$object = array_pop($this->stack);
121
					if(is_array($object) && is_array($object["data"])){
122
						$this->saveObject($object["data"]);
123
					}
124
				}
125
			}
126
		}
127
128
	}
129
130
	function saveObject(&$objdata){
131
		/*
132
			1) object data
133
			2) object templates
134
			3) object grants
135
			4) object files
136
		 */
137
		debug("WDDX working on ".$objdata['path'],'all');
138
139
		if ( $this->config['srcpath'] != $this->config['dstpath'] ){
140
			if ( strpos( $objdata['path'], $this->config['srcpath'] ) === 0 ){
141
				$objdata['path'] = $this->config['dstpath'].substr($objdata['path'],strlen($this->config['srcpath']));
142
			}
143
		}
144
145
		if($this->config['prefix']){
146
			$path = $this->store->make_path($this->config['prefix'],"./".$objdata['path']);
147
		} else {
148
			$this->print_verbose("prefixless: ".$this->config['srcpath'].":".$objdata['path']."\n");
149
			$path = $this->store->make_path($this->config['srcpath'], $objdata['path']);
150
		}
151
152
153
		$this->print_verbose('Importing: '.$path.' ');
154
		if($this->linktable[$objdata['id']]){
155
			$this->linkObject($path,$this->linktable[$objdata['id']]);
156
		} else {
157
			$this->linktable[$objdata['id']] = $path;
158
			$this->storeObject($path,$objdata);
159
		}
160
	}
161
162
	function linkObject($path,$linkpath){
163
		$this->print_verbose(" ( linking ) \n");
164
		$this->store->link($linkpath,$path);
165
		if($object->error){
166
			debug("WDDX link: error during save");
167
			debug("WDDX link: ".$object->error);
0 ignored issues
show
Bug introduced by
The variable $object 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...
168
		}
169
	}
170
171
	function storeObject($path,&$objdata){
172
	global $AR;
173
		/*
174
			step 1
175
			if not skip data
176
			load object if exists
177
			copy data into object
178
			else
179
			create new object
180
			fi
181
			save
182
			fi
183
		 */
184
		if(!($this->config['skipdata'] === true))
185
		{
186
			debug('WDDX work data','all');
187
			if($id = $this->store->exists($path))
0 ignored issues
show
Unused Code introduced by
$id 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...
188
			{
189
				debug("WDDX data: object exists",'all');
190 View Code Duplication
				if(!is_object($object)){
0 ignored issues
show
Bug introduced by
The variable $object seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
191
					$object = current(
192
							$this->store->call("system.get.phtml",
193
								array(),$this->store->get($path))
194
							);
195
				}
196
				if(
197
						($object->lastchanged <= $objdata['lastchanged']) ||
198
						($this->config['forcedata'] === true))
199
				{
200
					$this->print_verbose(" ( updating ) \n");
201
202
					$tmpconfig = $object->data->config;
0 ignored issues
show
Bug introduced by
The variable $object 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...
203
					unset($object->data);
204
					$object->data = $objdata['data'];
205
					$object->data->config->grants = $tmpconfig->grants;
206
					$object->data->config->pinp = $tmpconfig->pinp;
207
					$object->data->config->templates = $tmpconfig->templates;
208
					$object->type = $objdata['type'];
209
					$object->vtype = $objdata['vtype'];
210
					$object->lastchanged = $objdata['lastchanged'];
211
					$object->size = $objdata['size'];
212
					$object->priority = $objdata['priority'];
213
					$object->type = $objdata['type'];
214
					$object->save($objdata['properties']);
215
				} else {
216
					$this->print_verbose(" ( skipping ) \n");
217
				}
218
			} else
219
			{
220
221
				debug("WDDX data: object doesn't exists",'all');
222
				$this->print_verbose(" ( saving ) \n");
223
				$parent = $this->store->make_path($path,'..');
224
				if($parent == $path){ $parent = '..'; }
225
				$object = $this->store->newobject($path,
226
						$parent, $objdata['type'],
227
						$objdata['data'], 0, $objdata['lastchanged'],
228
						$objdata['vtype'], $objdata['size'], $objdata['priority']);
229
230
				$object->arIsNewObject = true;
231
232
				if(!$object->store->is_supported('fulltext')){
233
					unset($objdata['properties']['fulltext']);
234
				}
235
236
				$object->save($objdata['properties']);
237
				if($object->error){
238
					debug("WDDX data: error during save");
239
					debug("WDDX data: ".$object->error);
240
				}
241
				debug("WDDX data: done save");
242
243
			}
244
			unset($object);
245
		}
246
247
		/*
248
			step 2
249
			if not skip templates
250
			if removeold
251
			remove old templates
252
			fi
253
			if update
254
			if forced
255
			save new templates
256
			else
257
			save new templates when newer
258
			fi
259
			else
260
			save new templates
261
			fi
262
			fi
263
		 */
264
		if(!($this->config['skiptemplates'] === true))
265
		{
266
			debug('WDDX work templates','all');
267
			if($id = $this->store->exists($path))
0 ignored issues
show
Unused Code introduced by
$id 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...
268
			{
269
				debug("WDDX templates: object exists",'all');
270 View Code Duplication
				if(!is_object($object)){
271
					$object = current(
272
							$this->store->call("system.get.phtml",
273
								array(),$this->store->get($path))
274
							);
275
				}
276
				$templates=$object->store->get_filestore("templates");
277
278
				/*
279
					purge templates
280
				 */
281
				if(($this->config['dellalltemplates'] === true))
282
				{
283
					/* delete all current templates */
284
					$templates->purge($object->id);
285
					$object->data->config->pinp = array();
286
					$object->data->config->templates = array();
287
				}
288
289
				/*
290
					do something about those templates
291
				 */
292
				if(is_Array($objdata['templates'])){
293
					$this->print_verbose("   Templates:\n");
294
					foreach($objdata['templates'] as $type => $tval)
295
					{
296
						if(is_array($tval))
297
						{
298
							foreach($tval as $function => $nval)
299
							{
300
								if(is_array($nval))
301
								{
302
									foreach($nval as $language => $val)
303
									{
304
										$file = $type.".".$function.".".$language;
305
										debug("WDDX templates: ".$object->id."working on template $file",'all');
306
										$pinp=new pinp($AR->PINP_Functions, "local->", "\$AR_this->_");
307
308
										$template = base64_decode($val['template']);
309
										$compiled=$pinp->compile(strtr($template,"\r",""));
310
										$this->print_verbose('              ');
311
										$this->print_verbose("[".$file."]: ");
312
313
										if($templates->exists($object->id,$file))
314
										{
315
											if(
316
													($val['mtime'] >= $templates->mtime($object->id,$file)) ||
317
													($this->config['forcedata'] === true)
318
											  )
319
											{
320
												debug('WDDX templates: overwrite existing template','all');
321
												$this->print_verbose(" saving\n");
322
												$templates->write($template, $object->id, $file.".pinp");
323
												$templates->touch($object->id,$file.".pinp",$val['mtime']);
324
												$templates->write($compiled, $object->id, $file);
325
												$templates->touch($object->id,$file,$val['mtime']);
326
												$object->data->config->pinp[$type][$function][$language]=$object->id;
327
												/* is it a default template ? */
328 View Code Duplication
												if( $objdata['data']->config->templates[$type][$function][$language] === $objdata['id'])
329
												{
330
													$object->data->config->templates[$type][$function][$language] = $object->id;
331
												}
332
												else { // remove pinp template from default templates list
333
													if (isset($object->data->config->templates[$type][$function][$language])) {
334
														unset($object->data->config->templates[$type][$function][$language]);
335
														if (count($object->data->config->templates[$type][$function])==0) {
336
															unset($object->data->config->templates[$type][$function]);
337
															if (count($object->data->config->templates[$type])==0) {
338
																unset($object->data->config->templates[$type]);
339
															}
340
341
														}
342
													}
343
												}
344
345
											} else {
346
												$this->print_verbose(" skipping\n");
347
											}
348
										}else
349
										{
350
											debug('WDDX templates: create template','all');
351
											$this->print_verbose(" saving\n");
352
											$templates->write($template, $object->id, $file.".pinp");
353
											$templates->touch($object->id,$file."pinp",$val['mtime']);
354
											$templates->write($compiled, $object->id, $file);
355
											$templates->touch($object->id,$file,$val['mtime']);
356
357
											$object->data->config->pinp[$type][$function][$language]=$object->id;
358
											/* is it a default template ? */
359 View Code Duplication
											if( $objdata['data']->config->templates[$type][$function][$language] === $objdata['id'])
360
											{
361
												$object->data->config->templates[$type][$function][$language] = $object->id;
362
											}
363
											else { // remove pinp template from default templates list
364
												if (isset($object->data->config->templates[$type][$function][$language])) {
365
													unset($object->data->config->templates[$type][$function][$language]);
366
													if (count($object->data->config->templates[$type][$function])==0) {
367
														unset($object->data->config->templates[$type][$function]);
368
														if (count($object->data->config->templates[$type])==0) {
369
															unset($object->data->config->templates[$type]);
370
														}
371
372
													}
373
												}
374
											}
375
										}
376
									}
377
								} else {
378
									debug("WDDX template: nval != array",'all');
379
								}
380
							}
381
						} else {
382
							debug("WDDX template: tval != array",'all');
383
						}
384
					}
385
				} else {
386
					debug("WDDX template: templates != array",'all');
387
				}
388
				$changed = true;
389
			}
390
		}
391
392
		/*
393
			step 3
394
			if not skip grants
395
			if removeold
396
			remove old grants
397
			fi
398
			if exists
399
			remove
400
			fi
401
			save grant
402
			fi
403
		 */
404
		if(!($this->config['skipgrants'] === true))
405
		{
406
			debug('WDDX work grants','all');
407
			if($id = $this->store->exists($path))
0 ignored issues
show
Unused Code introduced by
$id 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...
408
			{
409
				debug('WDDX grants: yeah the path exists','all');
410 View Code Duplication
				if(!is_object($object)){
411
					$object = current(
412
							$this->store->call("system.get.phtml",
413
								array(),$this->store->get($path))
414
							);
415
				}
416
				if(is_array($objdata['data']->config->grants)){
417
					$this->print_verbose("   Grants: installing\n");
418
					$object->data->config->grants = $objdata['data']->config->grants;
419
					$changed = true;
420
				}
421
			}
422
		}
423
424
		/*
425
			step 4
426
			if not skip files
427
			if removeold
428
			remove old files
429
			fi
430
			if update
431
			if forced
432
			save new files
433
			else
434
			save new files when newer
435
			fi
436
			else
437
			save new files
438
			fi
439
			fi
440
		 */
441
		if(!($this->config['skipfiles'] === true))
442
		{
443
			debug('WDDX work files','all');
444
			if($id = $this->store->exists($path))
0 ignored issues
show
Unused Code introduced by
$id 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...
445
			{
446 View Code Duplication
				if(!is_object($object)){
447
					$object = current(
448
							$this->store->call("system.get.phtml",
449
								array(),$this->store->get($path))
450
							);
451
				}
452
453
				$files=$object->store->get_filestore("files");
454
				debug('WDDX files: yeah the path exists','all');
455
456
				if(is_Array($objdata[files]) && count($objdata[files]) > 0)
457
				{
458
					$this->print_verbose("       Files:\n");
459
					foreach($objdata[files] as $key => $val)
460
					{
461
						$this->print_verbose('              ');
462
						$this->print_verbose("[".$key."]: ");
463
						if($files->exists($object->id,$key))
464
						{
465
							if(
466
									($val['mtime'] >= $files->mtime($object->id,$key)) ||
467
									($this->config['forcefiles'] === true)
468
							  )
469
							{
470
								debug('WDDX files: overwrite existing file','all');
471
								$this->print_verbose(" updating\n");
472
								$files->write(base64_decode($val[file]), $object->id, $key);
473
								$files->touch($object->id,$file,$val['mtime']);
0 ignored issues
show
Bug introduced by
The variable $file 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...
474
							} else {
475
								$this->print_verbose(" skipping\n");
476
							}
477
						}else
478
						{
479
							$this->print_verbose(" saving\n");
480
							debug('WDDX files: create template','all');
481
							$files->write(base64_decode($val[file]), $object->id, $key);
482
							debug("WDDX files: touch $file with".$val['mtime'],'all');
483
							$files->touch($object->id,$file,$val['mtime']);
484
						}
485
					}
486
				}
487
			}
488
		}
489
		// save the object
490
		if($changed){
0 ignored issues
show
Bug introduced by
The variable $changed 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...
491
			$object->save();
492
		}
493
	}
494
495
	function characterData($parser, $data) {
0 ignored issues
show
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
496
		$element = &$this->stack[count($this->stack)-1];
497
		if (!$element["locked"]) {
498
			switch ($element["type"]) {
499
				case "number":
500
					$element["data"] = (int)$data;
501
				break;
502
				case "boolean":
503
					switch ($data) {
504
						case "true":
505
							$element["data"] = true;
506
						break;
507
						default:
508
						$element["data"] = false;
509
					}
510
				break;
511
				case "string":
512
					$element["data"] .= $data;
513
				break;
514
			}
515
		}
516
	}
517
518
	function parse($in,$store) {
519
		require_once($store->get_config("code")."modules/mod_pinp.phtml");
520
		$this->input = $in;
521
		$this->store = $store;
522
		$this->seenconfig = false;
523
		while (!feof($this->input)){
524
			$data = fgets($this->input, 65535);
525
			if (!xml_parse($this->xml_parser, $data, feof($this->input))) {
526
				die(sprintf("XML error: %s at line %d column %d \n",
0 ignored issues
show
Coding Style Compatibility introduced by
The method parse() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
527
							xml_error_string(xml_get_error_code($this->xml_parser)),
528
							xml_get_current_line_number($this->xml_parser),
529
							xml_get_current_column_number($this->xml_parser)));
530
			}
531
		}
532
		xml_parser_free($this->xml_parser);
533
	}
534
}
535