Completed
Push — master ( e5ef44...29e0f1 )
by Auke
18s
created

code.php ➔ wgWizKeepVars()   C

Complexity

Conditions 17
Paths 160

Size

Total Lines 68
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 306
Metric Value
cc 17
eloc 39
nc 160
nop 2
dl 0
loc 68
rs 5.2532
ccs 0
cts 49
cp 0
crap 306

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
  /******************************************************************
3
   code.php					   Muze Ariadne v2.1
4
   ------------------------------------------------------------------
5
6
   No result.
7
8
  ******************************************************************/
9
global $ARnls;
10
$ARnls->load('ariadne', $this->reqnls);
11
12
if( !function_exists("wgWizKeepVars") ) {
13
	function wgWizKeepVars($array, $prefix="") {
14
		// this function translates the given array to a list
15
		// of hidden input types. When $ARCurrent->override is on
16
		// there is no check to see wether a given variable
17
		// has already been seen and $ARCurrent->seenit is set.
18
		// In the case of an array, seenit is set to the name of
19
		// the array (for each element). In the case of a normal
20
		// variable, seenit is set to that variable's name.
21
		// When $ARCurrent->override is not set, each variable is
22
		// first checked against the 'seenit' array. If it is an
23
		// element of an array, seenit is checked against the name
24
		// of the array, else it is checked against the name of
25
		// the variable itself.
26
		// Only 'leaf' node or array elements are checked.
27
28
		global $ARCurrent, $AR;
29
		if (!$prefix) {
30
			$prefix="arStoreVars";
31
		}
32
		$prefix.="[";
33
		if ($prefix==="arStoreVars[") {
34
			$toplevel=true;
35
		}
36
		if (!($regexp=$ARCurrent->regexp)) {
37
			$regexp='/^arStoreVars\[(';
38
			reset($AR->nls->list);
39
			foreach( $AR->nls->list as $key => $value ) {
40
				$regexp.=$key.'|';
41
			}
42
			$regexp=substr($regexp,0,-1).')\]\[$/';
43
			$ARCurrent->regexp=$regexp;
44
		}
45
		if (preg_match($ARCurrent->regexp, $prefix)) {
46
			$toplevel=true;
47
		}
48
		$postfix="]";
49
50
		$ignoreVars = array(
51
			"wgWizAction" => true,
52
		);
53
54
		if( is_array($array ) ) {
55
			reset($array);
56
			foreach( $array as $key => $value ) {
57
				if( !$ignoreVars[$key] ) {
58
					if (is_array($value)) {
59
						if ($key!=="arStoreVars") {
60
							wgWizKeepVars($value, $prefix.$key.$postfix);
61
						}
62
					} elseif ($ARCurrent->override) { // don't check $ARCurrent->seenit, do set it.
63
						if ($toplevel) { // this is a normal name-value pair
0 ignored issues
show
Bug introduced by
The variable $toplevel 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...
64
							$ARCurrent->seenit[$prefix.$key.$postfix]=true;
65
						} else { // it's part of an array
66
							$ARCurrent->seenit[$prefix]=true;
67
						}
68
						$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
69
						echo "<input type=\"hidden\" name=\"".$prefix.$key.$postfix."\" value=\"".$value."\">\n";
70
					} elseif (!$ARCurrent->seenit[$prefix] && !$toplevel) { // value part of array
71
						$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
72
						echo "<input type=\"hidden\" name=\"".$prefix.$key.$postfix."\" value=\"".$value."\">\n";
73
					} elseif (!$ARCurrent->seenit[$prefix.$key.$postfix] && $toplevel) { // value not in array
74
						$value = htmlentities($value, ENT_QUOTES, 'UTF-8');
75
						echo "<input type=\"hidden\" name=\"".$prefix.$key.$postfix."\" value=\"".$value."\">\n";
76
					}
77
				}
78
			}
79
		}
80
	}
81
}
82
83
if( !class_exists('pinp_wizard', false) ) {
84
	class pinp_wizard {
85
		function _wgWizKeepVars($array, $prefix="") {
86
			return wgWizKeepVars($array, $prefix);
87
		}
88
	}
89
}
90
91
if( !function_exists("wgWizGetAction") ) {
92
	function wgWizGetAction($wgWizButtonPressed) {
93
		global $ARnls;
94
		$arReverseControl[$ARnls["next"]." >"]="next";
0 ignored issues
show
Coding Style Comprehensibility introduced by
$arReverseControl was never initialized. Although not strictly required by PHP, it is generally a good practice to add $arReverseControl = 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...
95
		$arReverseControl["< ".$ARnls["prev"]]="prev";
96
		$arReverseControl[$ARnls["save"]]="save";
97
		$arReverseControl[$ARnls["back"]]="back";
98
		$arReverseControl[$ARnls["cancel"]]="cancel";
99
		return $arReverseControl[$wgWizButtonPressed];
100
	}
101
}
102
	// code for pinp: calculate and return (preliminary) wgWizNextStep
103
	if (!$wgWizControl) {
104
		$wgWizControl=$this->getdata("wgWizControl","none");
105
	}
106
	if ($wgWizControl) {
107
		$wgResult=wgWizGetAction($wgWizControl);
108
	}
109
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
110