Completed
Pull Request — develop (#725)
by Agel_Nash
08:07
created

Modifiers::str_word_count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace EvolutionCMS\Legacy;
2
3
use EvolutionCMS\Interfaces\ModifiersInterface;
4
use DataGrid;
5
6
class Modifiers implements ModifiersInterface{
7
    /**
8
     * @var array
9
     */
10
    public $placeholders = array();
11
    /**
12
     * @var array
13
     */
14
    public $vars = array();
15
    /**
16
     * @var array
17
     */
18
    public $tmpCache = array();
19
    /**
20
     * @var
21
     */
22
    public $bt;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $bt. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
23
    /**
24
     * @var
25
     */
26
    public $srcValue;
27
    /**
28
     * @var array
29
     */
30
    public $condition = array();
31
    /**
32
     * @var string
33
     */
34
    public $condModifiers;
35
36
    /**
37
     * @var
38
     */
39
    public $key;
40
    /**
41
     * @var
42
     */
43
    public $value;
44
    /**
45
     * @var
46
     */
47
    public $opt;
48
    /**
49
     * @var
50
     */
51
    public $elmName;
52
53
    /**
54
     * @var array
55
     */
56
    public $documentObject = array();
57
58
    /**
59
     * MODIFIERS constructor.
60
     */
61
    public function __construct()
62
    {
63
        $modx = evolutionCMS();
64
        if (function_exists('mb_internal_encoding')) mb_internal_encoding($modx->config['modx_charset']);
65
        $this->condModifiers = '=,is,eq,equals,ne,neq,notequals,isnot,isnt,not,%,isempty,isnotempty,isntempty,>=,gte,eg,gte,greaterthan,>,gt,isgreaterthan,isgt,lowerthan,<,lt,<=,lte,islte,islowerthan,islt,el,find,in,inarray,in_array,fnmatch,wcard,wcard_match,wildcard,wildcard_match,is_file,is_dir,file_exists,is_readable,is_writable,is_image,regex,preg,preg_match,memberof,mo,isinrole,ir';
66
    }
67
68
    /**
69
     * @param string $key
70
     * @param string $value
71
     * @param string $modifiers
72
     * @return bool|mixed|string
73
     */
74
    public function phxFilter($key,$value,$modifiers)
75
    {
76
        $modx = evolutionCMS();
0 ignored issues
show
Unused Code introduced by
$modx 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...
77
        if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value);
78
        $this->srcValue = $value;
79
        $modifiers = trim($modifiers);
80
        $modifiers = ':'.trim($modifiers,':');
81
        $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers);
82
        $modifiers = $this->splitEachModifiers($modifiers);
83
84
        $this->placeholders = array();
85
        $this->placeholders['phx'] = '';
86
        $this->placeholders['dummy'] = '';
87
        $this->condition = array();
88
        $this->vars = array();
89
        $this->vars['name']    = & $key;
90
        $value = $this->parsePhx($key,$value,$modifiers);
91
        $this->vars = array();
92
        return $value;
93
    }
94
95
    /**
96
     * @param string $mode
97
     * @param string $modifiers
98
     * @return bool|string
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use false|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
99
     */
100
    public function _getDelim($mode,$modifiers) {
101
        $c = substr($modifiers,0,1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
102
        if(!in_array($c, array('"', "'", '`')) ) return false;
103
104
        $modifiers = substr($modifiers,1);
105
        $closure = $mode=='(' ? "{$c})" : $c;
106
        if(strpos($modifiers, $closure)===false) return false;
107
108
        return  $c;
109
    }
110
111
    /**
112
     * @param string $mode
113
     * @param string $delim
114
     * @param string $modifiers
115
     * @return bool|string
116
     */
117
    public function _getOpt($mode,$delim,$modifiers) {
118
        if($delim) {
119
            if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
120
121
            return substr($modifiers,1,strpos($modifiers,$delim,1)-1);
122
        }
123
        else {
124
            if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') );
125
126
            $chars = str_split($modifiers);
127
            $opt='';
128
            foreach($chars as $c) {
129
                if($c==':' || $c==')') break;
130
                $opt .=$c;
131
            }
132
            return $opt;
133
        }
134
    }
135
    public function _getRemainModifiers($mode,$delim,$modifiers) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
136
        if($delim) {
137
            if($mode=='(')
138
                return $this->_fetchContent($modifiers, $delim . ')');
139
            else {
140
                $modifiers = trim($modifiers);
141
                $modifiers = substr($modifiers,1);
142
                return $this->_fetchContent($modifiers, $delim);
143
            }
144
        }
145
        else {
146
            if($mode=='(') return $this->_fetchContent($modifiers, ')');
147
            $chars = str_split($modifiers);
148
            foreach($chars as $c) {
149
                if($c==':') return $modifiers;
150
                else $modifiers = substr($modifiers,1);
151
            }
152
            return $modifiers;
153
        }
154
    }
155
156
    public function _fetchContent($string,$delim) {
157
        $len = strlen($delim);
158
        $string = $this->parseDocumentSource($string);
159
        return substr($string,strpos($string, $delim)+$len);
160
    }
161
162
    public function splitEachModifiers($modifiers) {
163
        $modx = evolutionCMS();
164
165
        $cmd = '';
166
        $bt = '';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $bt. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
167
        $result = array();
168
        while($bt!==$modifiers) {
169
            $bt = $modifiers;
170
            $c = substr($modifiers,0,1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
171
            $modifiers = substr($modifiers,1);
172
173
            if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>=
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
174
                $c = substr($modifiers,strlen($match[1]),1);
175
                $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]";
176
                if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1);
177
                else         $modifiers = substr($modifiers,strlen($match[1]));
178
179
                $delim     = $this->_getDelim($c,$modifiers);
180
                $opt       = $this->_getOpt($c,$delim,$modifiers);
0 ignored issues
show
Security Bug introduced by
It seems like $delim defined by $this->_getDelim($c, $modifiers) on line 179 can also be of type false; however, EvolutionCMS\Legacy\Modifiers::_getOpt() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
181
                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
182
183
                $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo);
184
                $cmd = '';
185
            }
186
            elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ...
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
187
                $modifiers = substr($modifiers,strlen($match[0]));
188
                $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]);
189
                $cmd = '';
190
            }
191
            elseif($c==='(' || $c==='=') {
192
                $modifiers = $m1 = trim($modifiers);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m1. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
193
                $delim     = $this->_getDelim($c,$modifiers);
194
                $opt       = $this->_getOpt($c,$delim,$modifiers);
0 ignored issues
show
Security Bug introduced by
It seems like $delim defined by $this->_getDelim($c, $modifiers) on line 193 can also be of type false; however, EvolutionCMS\Legacy\Modifiers::_getOpt() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
195
                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
196
                $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]";
197
198
                $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
199
200
                $cmd = '';
201
            }
202
            elseif($c==':') {
203
                $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]";
204
                if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
205
206
                $cmd = '';
207
            }
208
            elseif(trim($modifiers)=='' && trim($cmd)!=='') {
209
                $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]";
210
                $cmd .= $c;
211
                $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
212
213
                break;
214
            }
215
            else {
216
                $cmd .= $c;
217
            }
218
        }
219
220
        if(empty($result)) return array();
221
222
        foreach($result as $i=>$a)
223
        {
224
            $a['opt'] = $this->parseDocumentSource($a['opt']);
225
            $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders);
226
        }
227
228
        return $result;
229
    }
230
231
    public function parsePhx($key,$value,$modifiers)
232
    {
233
        $modx = evolutionCMS();
0 ignored issues
show
Unused Code introduced by
$modx 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...
234
        $lastKey = '';
235
        $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true)));
236
        if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
237
        if(empty($modifiers)) return '';
238
239
        foreach($modifiers as $m)
240
        {
241
            $lastKey = strtolower($m['cmd']);
242
        }
243
        $_ = explode(',',$this->condModifiers);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $_. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
244
        if(in_array($lastKey,$_))
245
        {
246
            $modifiers[] = array('cmd'=>'then','opt'=>'1');
247
            $modifiers[] = array('cmd'=>'else','opt'=>'0');
248
        }
249
250
        foreach($modifiers as $i=>$a)
251
        {
252
            $value = $this->Filter($key,$value, $a['cmd'], $a['opt']);
253
        }
254
        $this->tmpCache[$cacheKey] = $value;
255
        return $value;
256
    }
257
258
    // Parser: modifier detection and eXtended processing if needed
259
    public function Filter($key, $value, $cmd, $opt='')
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
260
    {
261
        $modx = evolutionCMS();
262
263
        if($key==='documentObject') $value = $modx->documentIdentifier;
264
        $cmd = $this->parseDocumentSource($cmd);
265 View Code Duplication
        if(preg_match('@^[1-9][/0-9]*$@',$cmd))
266
        {
267
            if(strpos($cmd,'/')!==false)
268
                $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
269
            $opt = $cmd;
270
            $cmd = 'id';
271
        }
272
273
        if(isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
274
        elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
275
        else                                           $this->elmName = '';
276
277
        $cmd = strtolower($cmd);
278
        if($this->elmName!=='')
279
            $value = $this->getValueFromElement($key, $value, $cmd, $opt);
280
        else
281
            $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
282
283
        $value = str_replace('[+key+]', $key, $value);
284
285
        return $value;
286
    }
287
288
    public function isEmpty($cmd,$value)
289
    {
290
        if($value!=='') return false;
291
292
        $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $_. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
293
        if(in_array($cmd,$_)) return false;
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !in_array($cmd, $_);.
Loading history...
294
        else                  return true;
295
    }
296
297
    public function getValueFromPreset($key, $value, $cmd, $opt)
298
    {
299
        $modx = evolutionCMS();
300
301
        if($this->isEmpty($cmd,$value)) return '';
302
303
        $this->key = $key;
304
        $this->value  = $value;
305
        $this->opt    = $opt;
306
307
        switch ($cmd)
308
        {
309
            #####  Conditional Modifiers
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
310
            case 'input':
311
            case 'if':
312
                if(!$opt) return $value;
313
                return $opt;
314
            case '=':
315
            case 'eq':
316
            case 'is':
317
            case 'equals':
318
                $this->condition[] = (int)($value == $opt); break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
319
            case 'neq':
320
            case 'ne':
321
            case 'notequals':
322
            case 'isnot':
323
            case 'isnt':
324
            case 'not':
325
                $this->condition[] = (int)($value != $opt);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
326
            case '%':
327
                $this->condition[] = (int)($value%$opt==0);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
328
            case 'isempty':
329
                $this->condition[] = (int)(empty($value)); break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
330
            case 'isntempty':
331
            case 'isnotempty':
332
                $this->condition[] = (int)(!empty($value)); break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
333
            case '>=':
334
            case 'gte':
335
            case 'eg':
336
            case 'isgte':
337
                $this->condition[] = (int)($value >= $opt);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
338
            case '<=':
339
            case 'lte':
340
            case 'el':
341
            case 'islte':
342
                $this->condition[] = (int)($value <= $opt);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
343
            case '>':
344
            case 'gt':
345
            case 'greaterthan':
346
            case 'isgreaterthan':
347
            case 'isgt':
348
                $this->condition[] = (int)($value > $opt);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
349
            case '<':
350
            case 'lt':
351
            case 'lowerthan':
352
            case 'islowerthan':
353
            case 'islt':
354
                $this->condition[] = (int)($value < $opt);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
355
            case 'find':
356
                $this->condition[] = (int)(strpos($value, $opt)!==false);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
357
            case 'inarray':
358
            case 'in_array':
359
            case 'in':
360
                $opt = explode(',', $opt);
361
                $this->condition[] = (int)(in_array($value, $opt)!==false);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
362
            case 'wildcard_match':
363
            case 'wcard_match':
364
            case 'wildcard':
365
            case 'wcard':
366
            case 'fnmatch':
367
                $this->condition[] = (int)(fnmatch($opt, $value)!==false);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
368
            case 'is_file':
369
            case 'is_dir':
370
            case 'file_exists':
371
            case 'is_readable':
372
            case 'is_writable':
373
                if(!$opt) $path = $value;
374
                else      $path = $opt;
375
                if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path');
0 ignored issues
show
Coding Style Compatibility introduced by
The method getValueFromPreset() 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...
376
                if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/');
377
                $this->condition[] = (int)($cmd($path)!==false);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
378
            case 'is_image':
379
                if(!$opt) $path = $value;
380
                else      $path = $opt;
381
                if(!is_file($path)) {$this->condition[]='0';break;}
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
382
                $_ = getimagesize($path);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $_. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
383
                $this->condition[] = (int)($_[0]);break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
384
            case 'regex':
385
            case 'preg':
386
            case 'preg_match':
387
            case 'isinrole':
388
                $this->condition[] = (int)(preg_match($opt,$value));break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
389
            case 'ir':
390
            case 'memberof':
391
            case 'mo':
392
                // Is Member Of  (same as inrole but this one can be stringed as a conditional)
393
                $this->condition[] = $this->includeMdfFile('memberof');
394
                break;
395
            case 'or':
396
                $this->condition[] = '||';break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
397
            case 'and':
398
                $this->condition[] = '&&';break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
399
            case 'show':
400 View Code Duplication
            case 'this':
401
                $conditional = implode(' ',$this->condition);
402
                $isvalid = (int)(eval("return ({$conditional});"));
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
403
                if ($isvalid) return $this->srcValue;
404
                return NULL;
405 View Code Duplication
            case 'then':
406
                $conditional = implode(' ',$this->condition);
407
                $isvalid = (int)eval("return ({$conditional});");
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
408
                if ($isvalid)  return $opt;
409
                return null;
410 View Code Duplication
            case 'else':
411
                $conditional = implode(' ',$this->condition);
412
                $isvalid = (int)eval("return ({$conditional});");
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
413
                if (!$isvalid) return $opt;
414
                break;
415
            case 'select':
416
            case 'switch':
417
                $raw = explode('&',$opt);
418
                $map = array();
419
                $c = count($raw);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
420
                for($m=0; $m<$c; $m++) {
421
                    $mi = explode('=',$raw[$m],2);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $mi. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
422
                    $map[$mi[0]] = $mi[1];
423
                }
424
                if(isset($map[$value])) return $map[$value];
425
                else                    return '';
426
            ##### End of Conditional Modifiers
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
427
428
            #####  Encode / Decode / Hash / Escape
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
429
            case 'htmlent':
430
            case 'htmlentities':
431
                return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']);
432
            case 'html_entity_decode':
433
            case 'decode_html':
434
            case 'html_decode':
435
                return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']);
436
            case 'esc':
437
            case 'escape':
438
                $value = preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
439
                return str_replace(array('[', ']', '`'),array('&#91;', '&#93;', '&#96;'),$value);
440
            case 'sql_escape':
441
            case 'encode_js':
442
                return $modx->getDatabase()->escape($value);
443
            case 'htmlspecialchars':
444
            case 'hsc':
445
            case 'encode_html':
446
            case 'html_encode':
447
                return preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
448
            case 'spam_protect':
449
                return str_replace(array('@','.'),array('&#64;','&#46;'),$value);
450
            case 'strip':
451
                if($opt==='') $opt = ' ';
452
                return preg_replace('/[\n\r\t\s]+/', $opt, $value);
453
            case 'strip_linefeeds':
454
                return str_replace(array("\n","\r"), '', $value);
455
            case 'notags':
456
            case 'strip_tags':
457
            case 'remove_html':
458
                if($opt!=='')
459
                {
460
                    $param = array();
461
                    foreach(explode(',',$opt) as $v)
462
                    {
463
                        $v = trim($v,'</> ');
464
                        $param[] = "<{$v}>";
465
                    }
466
                    $params = implode(',',$param);
467
                }
468
                else $params = '';
469 View Code Duplication
                if(!strpos($params,'<br>')===false) {
470
                    $value = preg_replace('@(<br[ /]*>)\n@','$1',$value);
471
                    $value = preg_replace('@<br[ /]*>@',"\n",$value);
472
                }
473
                return $this->strip_tags($value,$params);
474
            case 'urlencode':
475
            case 'url_encode':
476
            case 'encode_url':
477
                return urlencode($value);
478
            case 'base64_decode':
479
                if($opt!=='false') $opt = true;
480
                else               $opt = false;
481
                return base64_decode($value,$opt);
482
            case 'encode_sha1': $cmd = 'sha1';
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
483
            case 'addslashes':
484
            case 'urldecode':
485
            case 'url_decode':
486
            case 'rawurlencode':
487
            case 'rawurldecode':
488
            case 'base64_encode':
489
            case 'md5':
490
            case 'sha1':
491
            case 'json_encode':
492
            case 'json_decode':
493
                return $cmd($value);
494
495
            #####  String Modifiers
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
496
            case 'lcase':
497
            case 'strtolower':
498
            case 'lower_case':
499
                return $this->strtolower($value);
500
            case 'ucase':
501
            case 'strtoupper':
502
            case 'upper_case':
503
                return $this->strtoupper($value);
504
            case 'capitalize':
505
                $_ = explode(' ',$value);
506
                foreach($_ as $i=>$v)
507
                {
508
                    $_[$i] = ucfirst($v);
509
                }
510
                return implode(' ',$_);
511 View Code Duplication
            case 'zenhan':
512
                if(empty($opt)) $opt='VKas';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
513
                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
514 View Code Duplication
            case 'hanzen':
515
                if(empty($opt)) $opt='VKAS';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
516
                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
517
            case 'str_shuffle':
518
            case 'shuffle':
519
                return $this->str_shuffle($value);
520
            case 'reverse':
521
            case 'strrev':
522
                return $this->strrev($value);
523
            case 'length':
524
            case 'len':
525
            case 'strlen':
526
            case 'count_characters':
527
                return $this->strlen($value);
528
            case 'count_words':
529
                $value = trim($value);
530
                return count(preg_split('/\s+/',$value));
531
            case 'str_word_count':
532
            case 'word_count':
533
            case 'wordcount':
534
                return $this->str_word_count($value);
535
            case 'count_paragraphs':
536
                $value = trim($value);
537
                $value = preg_replace('/\r/', '', $value);
538
                return count(preg_split('/\n+/',$value));
539
            case 'strpos':
540
                if($opt!=0&&empty($opt)) return $value;
541
                return $this->strpos($value,$opt);
542
            case 'wordwrap':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
543
                // default: 70
544
                $wrapat = (int)$opt > 0 ? (int)$opt : 70;
0 ignored issues
show
Unused Code introduced by
$wrapat 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...
545
                if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap');
546
                else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
547
            case 'wrap_text':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
548
                $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70;
549
                if($modx->config['manager_language']==='japanese-utf8') {
550
                    $chunk = array();
551
                    $bt='';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $bt. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
552
                    while($bt!=$value) {
553
                        $bt = $value;
554
                        if($this->strlen($value)<$width) {
555
                            $chunk[] = $value;
556
                            break;
557
                        }
558
                        $chunk[] = $this->substr($value,0,$width);
559
                        $value = $this->substr($value,$width);
560
                    }
561
                    return implode("\n",$chunk);
562
                }
563
                else
564
                    return wordwrap($value,$width,"\n",true);
565
            case 'substr':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
566
                if(empty($opt)) break;
567
                if(strpos($opt,',')!==false) {
568
                    list($b,$e) = explode(',',$opt,2);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
569
                    return $this->substr($value,$b,(int)$e);
570
                }
571
                else return $this->substr($value,$opt);
572
            case 'limit':
573
            case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html
574 View Code Duplication
                if(strpos($opt,'+')!==false)
575
                    list($len,$str) = explode('+',$opt,2);
576
                else {
577
                    $len = $opt;
578
                    $str = '';
579
                }
580
                if($len==='') $len = 100;
581
                if(abs($len) > $this->strlen($value)) $str ='';
582
                if(preg_match('/^[1-9][0-9]*$/',$len)) {
583
                    return $this->substr($value,0,$len) . $str;
584
                }
585
                elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
586
                    return $str . $this->substr($value,$len);
587
                }
588
                break;
589
            case 'summary':
590
            case 'smart_description':
591
            case 'smart_desc':
592
                return $this->includeMdfFile('summary');
593
            case 'replace':
594
            case 'str_replace':
595
                if(empty($opt) || strpos($opt,',')===false) break;
596
                if    (substr_count($opt, ',') ==1) $delim = ',';
597
                elseif(substr_count($opt, '|') ==1) $delim = '|';
598
                elseif(substr_count($opt, '=>')==1) $delim = '=>';
599
                elseif(substr_count($opt, '/') ==1) $delim = '/';
600
                else break;
601
                list($s,$r) = explode($delim,$opt);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $s. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
602
                if($value!=='') return str_replace($s,$r,$value);
603
                break;
604
            case 'replace_to':
605
            case 'tpl':
606 View Code Duplication
                if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
607
                break;
608
            case 'eachtpl':
609
                $value = explode('||',$value);
610
                $_ = array();
611
                foreach($value as $v) {
612
                    $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt);
613
                }
614
                return implode("\n", $_);
615
            case 'array_pop':
616
            case 'array_shift':
617
                if(strpos($value,'||')!==false) $delim = '||';
618
                else                            $delim = ',';
619
                return $cmd(explode($delim,$value));
620
            case 'preg_replace':
621
            case 'regex_replace':
622
                if(empty($opt) || strpos($opt,',')===false) break;
623
                list($s,$r) = explode(',',$opt,2);
624
                if($value!=='') return preg_replace($s,$r,$value);
625
                break;
626
            case 'cat':
627
            case 'concatenate':
628
            case '.':
629
                if($value!=='') return $value . $opt;
630
                break;
631
            case 'sprintf':
632
            case 'string_format':
633
                if($value!=='') return sprintf($opt,$value);
634
                break;
635
            case 'number_format':
636
                if($opt=='') $opt = 0;
637
                return number_format($value,$opt);
638
            case 'money_format':
639
                setlocale(LC_MONETARY,setlocale(LC_TIME,0));
640
                if($value!=='') return money_format($opt,(double)$value);
641
                break;
642
            case 'tobool':
643
                return boolval($value);
644
            case 'nl2lf':
645 View Code Duplication
                if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value);
646
                break;
647
            case 'br2nl':
648
                return preg_replace('@<br[\s/]*>@i', "\n", $value);
649
            case 'nl2br':
650
                if (version_compare(PHP_VERSION, '5.3.0', '<'))
651
                    return nl2br($value);
652
                if($opt!=='')
653
                {
654
                    $opt = trim($opt);
655
                    $opt = strtolower($opt);
656
                    if($opt==='false') $opt = false;
657
                    elseif($opt==='0') $opt = false;
658
                    else               $opt = true;
659
                }
660
                elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
661
                    $opt = false;
662
                else                   $opt = true;
663
                return nl2br($value,$opt);
664
            case 'ltrim':
665
            case 'rtrim':
666
            case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html
667
                if($opt==='')
668
                    return $cmd($value);
669
                else return $cmd($value,$opt);
670
            // These are all straight wrappers for PHP functions
671
            case 'ucfirst':
672
            case 'lcfirst':
673
            case 'ucwords':
674
                return $cmd($value);
675
676
            #####  Date time format
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
677
            case 'strftime':
678
            case 'date':
679
            case 'dateformat':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
680
                if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
681
                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
682
                if(strpos($opt,'%')!==false)
683
                    return strftime($opt,0+$value);
684
                else
685
                    return date($opt,0+$value);
686
            case 'time':
687
                if(empty($opt)) $opt = '%H:%M';
688
                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
689
                return strftime($opt,0+$value);
690
            case 'strtotime':
691
                return strtotime($value);
692
            #####  mathematical function
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
693
            case 'toint':
694
                return (int)$value;
695
            case 'tofloat':
696
                return floatval($value);
697
            case 'round':
698
                if(!$opt) $opt = 0;
699
                return $cmd($value,$opt);
700
            case 'max':
701
            case 'min':
702
                return $cmd(explode(',',$value));
703
            case 'floor':
704
            case 'ceil':
705
            case 'abs':
706
                return $cmd($value);
707
            case 'math':
708
            case 'calc':
709
                $value = (int)$value;
710
                if(empty($value)) $value = '0';
711
                $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt);
712
                $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter);
713
                if(strpos($filter,'?')===false) $filter = "?{$filter}";
714
                $filter = str_replace('?',$value,$filter);
715
                return eval("return {$filter};");
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
716
            case 'count':
717
                if($value=='') return 0;
718
                $value = explode(',',$value);
719
                return count($value);
720
            case 'sort':
721
            case 'rsort':
722
                if(strpos($value,"\n")!==false) $delim="\n";
723
                else $delim = ',';
724
                $swap = explode($delim,$value);
725
                if(!$opt) $opt = SORT_REGULAR;
726
                else      $opt = constant($opt);
727
                $cmd($swap,$opt);
728
                return implode($delim,$swap);
729
            #####  Resource fields
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
730
            case 'id':
731
                if($opt) return $this->getDocumentObject($opt,$key);
732
                break;
733
            case 'type':
734
            case 'contenttype':
735
            case 'pagetitle':
736
            case 'longtitle':
737
            case 'description':
738
            case 'alias':
739
            case 'introtext':
740
            case 'link_attributes':
741
            case 'published':
742
            case 'pub_date':
743
            case 'unpub_date':
744
            case 'parent':
745
            case 'isfolder':
746
            case 'content':
747
            case 'richtext':
748
            case 'template':
749
            case 'menuindex':
750
            case 'searchable':
751
            case 'cacheable':
752
            case 'createdby':
753
            case 'createdon':
754
            case 'editedby':
755
            case 'editedon':
756
            case 'deleted':
757
            case 'deletedon':
758
            case 'deletedby':
759
            case 'publishedon':
760
            case 'publishedby':
761
            case 'menutitle':
762
            case 'donthit':
763
            case 'haskeywords':
764
            case 'privateweb':
765
            case 'privatemgr':
766
            case 'content_dispo':
767
            case 'hidemenu':
768
                if($cmd==='contenttype') $cmd = 'contentType';
769
                return $this->getDocumentObject($value,$cmd);
770
            case 'title':
771
                $pagetitle = $this->getDocumentObject($value,'pagetitle');
772
                $longtitle = $this->getDocumentObject($value,'longtitle');
773
                return $longtitle ? $longtitle : $pagetitle;
774
            case 'shorttitle':
775
                $pagetitle = $this->getDocumentObject($value,'pagetitle');
776
                $menutitle = $this->getDocumentObject($value,'menutitle');
777
                return $menutitle ? $menutitle : $pagetitle;
778
            case 'templatename':
779
                $rs = $modx->getDatabase()->select('templatename','[+prefix+]site_templates',"id='{$value}'");
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $rs. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
780
                $templateName = $modx->getDatabase()->getValue($rs);
0 ignored issues
show
Bug introduced by
It seems like $rs defined by $modx->getDatabase()->se...ates', "id='{$value}'") on line 779 can also be of type boolean; however, EvolutionCMS\Database::getValue() does only seem to accept object<mysqli_result>|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
781
                return !$templateName ? '(blank)' : $templateName;
782
            case 'getfield':
783
                if(!$opt) $opt = 'content';
784
                return $modx->getField($opt,$value);
785
            case 'children':
786
            case 'childids':
787
                if($value=='') $value = 0; // 値がない場合はルートと見なす
788
                $published = 1;
789
                if($opt=='') $opt = 'page';
790
                $_ = explode(',',$opt);
791
                $where = array();
792
                foreach($_ as $opt) {
793
                    switch(trim($opt)) {
794
                        case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break;
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
795
                        case 'folder'; case 'isfolder':                $where[] = 'sc.isfolder=1'; break;
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
796
                        case  'menu';  case  'show_menu':              $where[] = 'sc.hidemenu=0'; break;
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
797
                        case '!menu';  case '!show_menu':              $where[] = 'sc.hidemenu=1'; break;
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
798
                        case  'published':                             $published = 1; break;
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
799
                        case '!published':                             $published = 0; break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
800
                    }
801
                }
802
                $where = implode(' AND ', $where);
803
                $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where);
804
                $result = array();
805
                foreach((array)$children as $child){
806
                    $result[] = $child['id'];
807
                }
808
                return implode(',', $result);
809
            case 'fullurl':
810
                if(!is_numeric($value)) return $value;
811
                return $modx->makeUrl($value);
812
            case 'makeurl':
813
                if(!is_numeric($value)) return $value;
814
                if(!$opt) $opt = 'full';
815
                return $modx->makeUrl($value,'','',$opt);
816
817
            #####  File system
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
818
            case 'getimageinfo':
819
            case 'imageinfo':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
820
                if(!is_file($value)) return '';
821
                $_ = getimagesize($value);
822
                if(!$_[0]) return '';
823
                $info['width']  = $_[0];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$info was never initialized. Although not strictly required by PHP, it is generally a good practice to add $info = 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...
824
                $info['height'] = $_[1];
825
                if    ($_[0] > $_[1]) $info['aspect'] = 'landscape';
826
                elseif($_[0] < $_[1]) $info['aspect'] = 'portrait';
827
                else                  $info['aspect'] = 'square';
828
                switch($_[2]) {
829
                    case IMAGETYPE_GIF  : $info['type'] = 'gif'; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
830
                    case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
831
                    case IMAGETYPE_PNG  : $info['type'] = 'png'; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
832
                    default             : $info['type'] = 'unknown';
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
833
                }
834
                $info['attrib'] = $_[3];
835
                switch($opt) {
836
                    case 'width' : return $info['width'];
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
837
                    case 'height': return $info['height'];
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
838
                    case 'aspect': return $info['aspect'];
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
839
                    case 'type'  : return $info['type'];
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
840
                    case 'attrib': return $info['attrib'];
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
841
                    default      : return print_r($info,true);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
842
                }
843
844
            case 'file_get_contents':
845
            case 'readfile':
846
                if(!is_file($value)) return $value;
847
                $value = realpath($value);
848
                if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file');
0 ignored issues
show
Coding Style Compatibility introduced by
The method getValueFromPreset() 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...
849
                $ext = strtolower(substr($value,-4));
850
                if($ext==='.php') exit('Can not read php file');
0 ignored issues
show
Coding Style Compatibility introduced by
The method getValueFromPreset() 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...
851
                if($ext==='.cgi') exit('Can not read cgi file');
0 ignored issues
show
Coding Style Compatibility introduced by
The method getValueFromPreset() 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...
852
                return file_get_contents($value);
853
            case 'filesize':
854
                if($value == '') return '';
855
                $filename = $value;
856
857
                $site_url = $modx->config['site_url'];
858
                if(strpos($filename,$site_url) === 0)
859
                    $filename = substr($filename,0,strlen($site_url));
860
                $filename = trim($filename,'/');
861
862
                $opt = trim($opt,'/');
863
                if($opt!=='') $opt .= '/';
864
865
                $filename = MODX_BASE_PATH.$opt.$filename;
866
867
                if(is_file($filename)){
868
                    clearstatcache();
869
                    $size = filesize($filename);
870
                    return $size;
871
                }
872
                else return '';
873
            #####  User info
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
874
            case 'username':
875
            case 'fullname':
876
            case 'role':
877
            case 'email':
878
            case 'phone':
879
            case 'mobilephone':
880
            case 'blocked':
881
            case 'blockeduntil':
882
            case 'blockedafter':
883
            case 'logincount':
884
            case 'lastlogin':
885
            case 'thislogin':
886
            case 'failedlogincount':
887
            case 'dob':
888
            case 'gender':
889
            case 'country':
890
            case 'street':
891
            case 'city':
892
            case 'state':
893
            case 'zip':
894
            case 'fax':
895
            case 'photo':
896
            case 'comment':
897
                $this->opt = $cmd;
898
                return $this->includeMdfFile('moduser');
899
            case 'userinfo':
900
                if(empty($opt)) $this->opt = 'username';
901
                return $this->includeMdfFile('moduser');
902
            case 'webuserinfo':
903
                if(empty($opt)) $this->opt = 'username';
904
                $this->value = -$value;
905
                return $this->includeMdfFile('moduser');
906
            #####  Special functions
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
907
            case 'ifempty':
908
            case '_default':
909
            case 'default':
910
                if (empty($value)) return $opt; break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
911
            case 'ifnotempty':
912
                if (!empty($value)) return $opt; break;
0 ignored issues
show
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
913
            case 'datagrid':
914
                include_once(MODX_CORE_PATH . 'controls/datagrid.class.php');
915
                $grd = new DataGrid(null, trim($value));
916
                $grd->itemStyle = '';
917
                $grd->altItemStyle = '';
918
                $pos = strpos($value,"\n");
919
                if($pos) $_ = substr($value,0,$pos);
920
                else $_ = $pos;
921
                $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ',';
922
                return $grd->render();
923
            case 'rotate':
924
            case 'evenodd':
925
                if(strpos($opt,',')===false) $opt = 'odd,even';
926
                $_ = explode(',', $opt);
927
                $c = count($_);
928
                $i = $value + $c;
929
                $i = $i % $c;
930
                return $_[$i];
931
            case 'takeval':
932
                $arr = explode(",",$opt);
933
                $idx = $value;
934
                if(!is_numeric($idx)) return $value;
935
                return $arr[$idx];
936
            case 'getimage':
937
                return $this->includeMdfFile('getimage');
938
            case 'nicesize':
939
                return $modx->nicesize($value);
940
            case 'googlemap':
941
            case 'googlemaps':
942
                if(empty($opt)) $opt = 'border:none;width:500px;height:350px;';
943
                $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>';
944
                $ph['style'] = $opt;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ph was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ph = 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...
Comprehensibility introduced by
Avoid variables with short names like $ph. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
945
                $ph['value'] = $value;
946
                return $modx->parseText($tpl,$ph);
947
            case 'youtube':
948
            case 'youtube16x9':
949
                if(empty($opt)) $opt = 560;
950
                $h = round($opt*0.5625);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $h. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
951
                $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>';
952
                return sprintf($tpl,$opt,$h,$value);
953
            //case 'youtube4x3':%s*0.75+25
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
954
            case 'setvar':
955
                $modx->placeholders[$opt] = $value;
956
                return '';
957
            case 'csstohead':
958
                $modx->regClientCSS($value);
959
                return '';
960
            case 'htmltohead':
961
                $modx->regClientStartupHTMLBlock($value);
962
                return '';
963
            case 'htmltobottom':
964
                $modx->regClientHTMLBlock($value);
965
                return '';
966
            case 'jstohead':
967
                $modx->regClientStartupScript($value);
968
                return '';
969
            case 'jstobottom':
970
                $modx->regClientScript($value);
971
                return '';
972
            case 'dummy':
973
                return $value;
974
975
            // If we haven't yet found the modifier, let's look elsewhere
976
            default:
977
                $value = $this->getValueFromElement($key, $value, $cmd, $opt);
978
        }
979
        return $value;
980
    }
981
982
    public function includeMdfFile($cmd) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
983
        $modx = evolutionCMS();
984
        $key = $this->key;
985
        $value  = $this->value;
986
        $opt    = $this->opt;
987
        return include(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php");
988
    }
989
990
    public function getValueFromElement($key, $value, $cmd, $opt)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
991
    {
992
        $modx = evolutionCMS();
993
        if( isset($modx->snippetCache[$this->elmName]) )
994
        {
995
            $php = $modx->snippetCache[$this->elmName];
996
        }
997
        else
998
        {
999
            $esc_elmName = $modx->getDatabase()->escape($this->elmName);
1000
            $result = $modx->getDatabase()->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'");
1001
            $total = $modx->getDatabase()->getRecordCount($result);
0 ignored issues
show
Bug introduced by
It seems like $result defined by $modx->getDatabase()->se...name='{$esc_elmName}'") on line 1000 can also be of type boolean; however, EvolutionCMS\Database::getRecordCount() does only seem to accept object<mysqli_result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1002
            if($total == 1)
1003
            {
1004
                $row = $modx->getDatabase()->getRow($result);
0 ignored issues
show
Bug introduced by
It seems like $result defined by $modx->getDatabase()->se...name='{$esc_elmName}'") on line 1000 can also be of type boolean; however, EvolutionCMS\Database::getRow() does only seem to accept object<mysqli_result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1005
                $php = $row['snippet'];
1006
            }
1007
            elseif($total == 0)
1008
            {
1009
                $assets_path = MODX_BASE_PATH.'assets/';
1010
                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1011
                    $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1012
                elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1013
                    $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1014
                elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1015
                    $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1016
                else $modifiers_path = false;
1017
1018
                if($modifiers_path !== false) {
1019
                    $php = @file_get_contents($modifiers_path);
1020
                    $php = trim($php);
1021
                    if(substr($php,0,5)==='<?php') $php = substr($php,6);
1022
                    if(substr($php,0,2)==='<?')    $php = substr($php,3);
1023
                    if(substr($php,-2)==='?>')     $php = substr($php,0,-2);
1024
                    if($this->elmName!=='')
1025
                        $modx->snippetCache[$this->elmName.'Props'] = '';
1026
                }
1027
                else
1028
                    $php = false;
1029
            }
1030
            else $php = false;
1031
            if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php;
1032
        }
1033
        if($php==='') $php=false;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
1034
1035
        if($php===false) $html = $modx->getChunk($this->elmName);
1036
        else             $html = false;
1037
1038
        $self = '[+output+]';
1039
1040
        if($php !== false)
1041
        {
1042
            ob_start();
1043
            $options = $opt;
0 ignored issues
show
Unused Code introduced by
$options 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...
1044
            $output = $value;
0 ignored issues
show
Unused Code introduced by
$output 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...
1045
            $name   = $key;
0 ignored issues
show
Unused Code introduced by
$name 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...
1046
            $this->bt = $value;
1047
            $this->vars['value']   = & $value;
1048
            $this->vars['input']   = & $value;
1049
            $this->vars['option']  = & $opt;
1050
            $this->vars['options'] = & $opt;
1051
            $custom = eval($php);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
1052
            $msg = ob_get_contents();
1053
            if($value===$this->bt) $value = $msg . $custom;
1054
            ob_end_clean();
1055
        }
1056
        elseif($html!==false && isset($value) && $value!=='')
1057
        {
1058
            $html = str_replace(array($self,'[+value+]'), $value, $html);
1059
            $value = str_replace(array('[+options+]','[+param+]'), $opt, $html);
1060
        }
1061
        else return false;
1062
1063
        if($php===false && $html===false && $value!==''
1064
            && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false))
1065
        {
1066
            $value = str_replace(array('[+value+]',$self),$value,$cmd);
1067
        }
1068
        return $value;
1069
    }
1070
1071
    public function parseDocumentSource($content='')
1072
    {
1073
        $modx = evolutionCMS();
1074
1075
        if(strpos($content,'[')===false && strpos($content,'{')===false) return $content;
1076
1077
        if(!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1078
        $bt='';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $bt. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
1079
        $i=0;
1080
        while($bt!==$content)
1081
        {
1082
            $bt = $content;
1083
            if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1084
                $content = $modx->mergeDocumentContent($content);
1085
            if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1086
            if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1087
            if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1088
            if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content);
1089
1090
            if($content===$bt)              break;
1091
            if($modx->maxParserPasses < $i) break;
1092
            $i++;
1093
        }
1094
        return $content;
1095
    }
1096
1097
    public function getDocumentObject($target='',$field='pagetitle')
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
1098
    {
1099
        $modx = evolutionCMS();
1100
1101
        $target = trim($target);
1102
        if(empty($target)) $target = $modx->config['site_start'];
1103
        if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id';
1104
        else $method = 'alias';
1105
1106
        if(!isset($this->documentObject[$target]))
1107
        {
1108
            $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct');
1109
        }
1110
1111
        if($this->documentObject[$target]['publishedon']==='0')
1112
            return '';
1113
        elseif(isset($this->documentObject[$target][$field]))
1114
        {
1115
            if(is_array($this->documentObject[$target][$field]))
1116
            {
1117
                $a = $modx->getTemplateVarOutput($field,$target);
0 ignored issues
show
Documentation introduced by
$field is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
1118
                $this->documentObject[$target][$field] = $a[$field];
1119
            }
1120
        }
1121
        else $this->documentObject[$target][$field] = false;
1122
1123
        return $this->documentObject[$target][$field];
1124
    }
1125
1126
    public function setPlaceholders($value = '', $key = '', $path = '') {
1127
        if($path!=='') $key = "{$path}.{$key}";
1128
        if (is_array($value)) {
1129
            foreach ($value as $subkey => $subval) {
1130
                $this->setPlaceholders($subval, $subkey, $key);
1131
            }
1132
        }
1133
        else $this->setModifiersVariable($key, $value);
1134
    }
1135
1136
    // Sets a placeholder variable which can only be access by Modifiers
1137
    public function setModifiersVariable($key, $value) {
1138
        if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1139
    }
1140
1141
    //mbstring
1142
    public function substr($str, $s, $l = null) {
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $s. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $l. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
1143
        $modx = evolutionCMS();
1144
        if(is_null($l)) $l = $this->strlen($str);
1145
        if (function_exists('mb_substr'))
1146
        {
1147
            if(strpos($str,"\r")!==false)
1148
                $str = str_replace(array("\r\n","\r"), "\n", $str);
1149
            return mb_substr($str, $s, $l, $modx->config['modx_charset']);
1150
        }
1151
        return substr($str, $s, $l);
1152
    }
1153
    public function strpos($haystack,$needle,$offset=0) {
1154
        $modx = evolutionCMS();
1155
        if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1156
        return strpos($haystack,$needle,$offset);
1157
    }
1158
    public function strlen($str) {
1159
        $modx = evolutionCMS();
1160
        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1161
        return strlen($str);
1162
    }
1163
    public function strtolower($str) {
1164
        if (function_exists('mb_strtolower')) return mb_strtolower($str);
1165
        return strtolower($str);
1166
    }
1167
    public function strtoupper($str) {
1168
        if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
1169
        return strtoupper($str);
1170
    }
1171
    public function ucfirst($str) {
1172
        if (function_exists('mb_strtoupper'))
1173
            return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1174
        return ucfirst($str);
1175
    }
1176
    public function lcfirst($str) {
1177
        if (function_exists('mb_strtolower'))
1178
            return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1179
        return lcfirst($str);
1180
    }
1181
    public function ucwords($str) {
1182
        if (function_exists('mb_convert_case'))
1183
            return mb_convert_case($str, MB_CASE_TITLE);
1184
        return ucwords($str);
1185
    }
1186
    public function strrev($str) {
1187
        preg_match_all('/./us', $str, $ar);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $ar. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
1188
        return implode(array_reverse($ar[0]));
1189
    }
1190
    public function str_shuffle($str) {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
1191
        preg_match_all('/./us', $str, $ar);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $ar. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
1192
        shuffle($ar[0]);
1193
        return implode($ar[0]);
1194
    }
1195
    public function str_word_count($str) {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
1196
        return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
1197
    }
1198
    public function strip_tags($value,$params='') {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
1199
        $modx = evolutionCMS();
0 ignored issues
show
Unused Code introduced by
$modx 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...
1200
1201 View Code Duplication
        if(stripos($params,'style')===false && stripos($value,'</style>')!==false) {
1202
            $value = preg_replace('@<style.*?>.*?</style>@is', '', $value);
1203
        }
1204 View Code Duplication
        if(stripos($params,'script')===false && stripos($value,'</script>')!==false) {
1205
            $value = preg_replace('@<script.*?>.*?</script>@is', '', $value);
1206
        }
1207
1208
        return trim(strip_tags($value,$params));
1209
    }
1210
}
1211