Completed
Push — develop ( 7e4f1d...c463ba )
by Dmytro
11:42 queued 04:02
created

MODIFIERS::_getOpt()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 6
nop 3
dl 0
loc 18
rs 8.2222
c 0
b 0
f 0
1
<?php
2
3
if(!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/');
4
5
class MODIFIERS {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
    /**
7
     * @var array
8
     */
9
    public $placeholders = array();
10
    /**
11
     * @var array
12
     */
13
    public $vars = array();
14
    /**
15
     * @var array
16
     */
17
    public $tmpCache = array();
18
    /**
19
     * @var
20
     */
21
    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...
22
    /**
23
     * @var
24
     */
25
    public $srcValue;
26
    /**
27
     * @var array
28
     */
29
    public $condition = array();
30
    /**
31
     * @var string
32
     */
33
    public $condModifiers;
34
35
    /**
36
     * @var
37
     */
38
    public $key;
39
    /**
40
     * @var
41
     */
42
    public $value;
43
    /**
44
     * @var
45
     */
46
    public $opt;
47
    /**
48
     * @var
49
     */
50
    public $elmName;
51
52
    /**
53
     * @var array
54
     */
55
    public $documentObject = array();
56
57
    /**
58
     * MODIFIERS constructor.
59
     */
60
    public function __construct()
61
    {
62
        $modx = evolutionCMS();
63
        if (function_exists('mb_internal_encoding')) mb_internal_encoding($modx->config['modx_charset']);
64
        $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';
65
    }
66
67
    /**
68
     * @param string $key
69
     * @param string $value
70
     * @param string $modifiers
71
     * @return bool|mixed|string
72
     */
73
    public function phxFilter($key,$value,$modifiers)
74
    {
75
        $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...
76
        if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value);
77
        $this->srcValue = $value;
78
        $modifiers = trim($modifiers);
79
        $modifiers = ':'.trim($modifiers,':');
80
        $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers);
81
        $modifiers = $this->splitEachModifiers($modifiers);
82
83
        $this->placeholders = array();
84
        $this->placeholders['phx'] = '';
85
        $this->placeholders['dummy'] = '';
86
        $this->condition = array();
87
        $this->vars = array();
88
        $this->vars['name']    = & $key;
89
        $value = $this->parsePhx($key,$value,$modifiers);
90
        $this->vars = array();
91
        return $value;
92
    }
93
94
    /**
95
     * @param string $mode
96
     * @param string $modifiers
97
     * @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...
98
     */
99
    public function _getDelim($mode,$modifiers) {
100
        $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...
101
        if(!in_array($c, array('"', "'", '`')) ) return false;
102
103
        $modifiers = substr($modifiers,1);
104
        $closure = $mode=='(' ? "{$c})" : $c;
105
        if(strpos($modifiers, $closure)===false) return false;
106
107
        return  $c;
108
    }
109
110
    /**
111
     * @param string $mode
112
     * @param string $delim
113
     * @param string $modifiers
114
     * @return bool|string
115
     */
116
    public function _getOpt($mode,$delim,$modifiers) {
117
        if($delim) {
118
            if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1);
119
120
            return substr($modifiers,1,strpos($modifiers,$delim,1)-1);
121
        }
122
        else {
123
            if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') );
124
125
            $chars = str_split($modifiers);
126
            $opt='';
127
            foreach($chars as $c) {
128
                if($c==':' || $c==')') break;
129
                $opt .=$c;
130
            }
131
            return $opt;
132
        }
133
    }
134
    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...
135
        if($delim) {
136
            if($mode=='(')
137
                return $this->_fetchContent($modifiers, $delim . ')');
138
            else {
139
                $modifiers = trim($modifiers);
140
                $modifiers = substr($modifiers,1);
141
                return $this->_fetchContent($modifiers, $delim);
142
            }
143
        }
144
        else {
145
            if($mode=='(') return $this->_fetchContent($modifiers, ')');
146
            $chars = str_split($modifiers);
147
            foreach($chars as $c) {
148
                if($c==':') return $modifiers;
149
                else $modifiers = substr($modifiers,1);
150
            }
151
            return $modifiers;
152
        }
153
    }
154
155
    public function _fetchContent($string,$delim) {
156
        $len = strlen($delim);
157
        $string = $this->parseDocumentSource($string);
158
        return substr($string,strpos($string, $delim)+$len);
159
    }
160
161
    public function splitEachModifiers($modifiers) {
162
        $modx = evolutionCMS();
163
164
        $cmd = '';
165
        $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...
166
        $result = array();
167
        while($bt!==$modifiers) {
168
            $bt = $modifiers;
169
            $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...
170
            $modifiers = substr($modifiers,1);
171
172
            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...
173
                $c = substr($modifiers,strlen($match[1]),1);
174
                $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]";
175
                if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1);
176
                else         $modifiers = substr($modifiers,strlen($match[1]));
177
178
                $delim     = $this->_getDelim($c,$modifiers);
179
                $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 178 can also be of type false; however, 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...
180
                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
181
182
                $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo);
183
                $cmd = '';
184
            }
185
            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...
186
                $modifiers = substr($modifiers,strlen($match[0]));
187
                $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]);
188
                $cmd = '';
189
            }
190
            elseif($c==='(' || $c==='=') {
191
                $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...
192
                $delim     = $this->_getDelim($c,$modifiers);
193
                $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 192 can also be of type false; however, 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...
194
                $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers));
195
                $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]";
196
197
                $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...
198
199
                $cmd = '';
200
            }
201
            elseif($c==':') {
202
                $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]";
203
                if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
204
205
                $cmd = '';
206
            }
207
            elseif(trim($modifiers)=='' && trim($cmd)!=='') {
208
                $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]";
209
                $cmd .= $c;
210
                $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo);
211
212
                break;
213
            }
214
            else {
215
                $cmd .= $c;
216
            }
217
        }
218
219
        if(empty($result)) return array();
220
221
        foreach($result as $i=>$a)
222
        {
223
            $a['opt'] = $this->parseDocumentSource($a['opt']);
224
            $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders);
225
        }
226
227
        return $result;
228
    }
229
230
    public function parsePhx($key,$value,$modifiers)
231
    {
232
        $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...
233
        $lastKey = '';
234
        $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true)));
235
        if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey];
236
        if(empty($modifiers)) return '';
237
238
        foreach($modifiers as $m)
239
        {
240
            $lastKey = strtolower($m['cmd']);
241
        }
242
        $_ = 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...
243
        if(in_array($lastKey,$_))
244
        {
245
            $modifiers[] = array('cmd'=>'then','opt'=>'1');
246
            $modifiers[] = array('cmd'=>'else','opt'=>'0');
247
        }
248
249
        foreach($modifiers as $i=>$a)
250
        {
251
            $value = $this->Filter($key,$value, $a['cmd'], $a['opt']);
252
        }
253
        $this->tmpCache[$cacheKey] = $value;
254
        return $value;
255
    }
256
257
    // Parser: modifier detection and eXtended processing if needed
258
    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...
259
    {
260
        $modx = evolutionCMS();
261
262
        if($key==='documentObject') $value = $modx->documentIdentifier;
263
        $cmd = $this->parseDocumentSource($cmd);
264 View Code Duplication
        if(preg_match('@^[1-9][/0-9]*$@',$cmd))
265
        {
266
            if(strpos($cmd,'/')!==false)
267
                $cmd = $this->substr($cmd,strrpos($cmd,'/')+1);
268
            $opt = $cmd;
269
            $cmd = 'id';
270
        }
271
272
        if(isset($modx->snippetCache["phx:{$cmd}"]))   $this->elmName = "phx:{$cmd}";
273
        elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}";
274
        else                                           $this->elmName = '';
275
276
        $cmd = strtolower($cmd);
277
        if($this->elmName!=='')
278
            $value = $this->getValueFromElement($key, $value, $cmd, $opt);
279
        else
280
            $value = $this->getValueFromPreset($key, $value, $cmd, $opt);
281
282
        $value = str_replace('[+key+]', $key, $value);
283
284
        return $value;
285
    }
286
287
    public function isEmpty($cmd,$value)
288
    {
289
        if($value!=='') return false;
290
291
        $_ = 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...
292
        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...
293
        else                  return true;
294
    }
295
296
    public function getValueFromPreset($key, $value, $cmd, $opt)
297
    {
298
        $modx = evolutionCMS();
299
300
        if($this->isEmpty($cmd,$value)) return '';
301
302
        $this->key = $key;
303
        $this->value  = $value;
304
        $this->opt    = $opt;
305
306
        switch ($cmd)
307
        {
308
            #####  Conditional Modifiers
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
309
            case 'input':
310
            case 'if':
311
                if(!$opt) return $value;
312
                return $opt;
313
            case '=':
314
            case 'eq':
315
            case 'is':
316
            case 'equals':
317
                $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...
318
            case 'neq':
319
            case 'ne':
320
            case 'notequals':
321
            case 'isnot':
322
            case 'isnt':
323
            case 'not':
324
                $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...
325
            case '%':
326
                $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...
327
            case 'isempty':
328
                $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...
329
            case 'isntempty':
330
            case 'isnotempty':
331
                $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...
332
            case '>=':
333
            case 'gte':
334
            case 'eg':
335
            case 'isgte':
336
                $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...
337
            case '<=':
338
            case 'lte':
339
            case 'el':
340
            case 'islte':
341
                $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...
342
            case '>':
343
            case 'gt':
344
            case 'greaterthan':
345
            case 'isgreaterthan':
346
            case 'isgt':
347
                $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...
348
            case '<':
349
            case 'lt':
350
            case 'lowerthan':
351
            case 'islowerthan':
352
            case 'islt':
353
                $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...
354
            case 'find':
355
                $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...
356
            case 'inarray':
357
            case 'in_array':
358
            case 'in':
359
                $opt = explode(',', $opt);
360
                $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...
361
            case 'wildcard_match':
362
            case 'wcard_match':
363
            case 'wildcard':
364
            case 'wcard':
365
            case 'fnmatch':
366
                $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...
367
            case 'is_file':
368
            case 'is_dir':
369
            case 'file_exists':
370
            case 'is_readable':
371
            case 'is_writable':
372
                if(!$opt) $path = $value;
373
                else      $path = $opt;
374
                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...
375
                if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/');
376
                $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...
377
            case 'is_image':
378
                if(!$opt) $path = $value;
379
                else      $path = $opt;
380
                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...
381
                $_ = 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...
382
                $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...
383
            case 'regex':
384
            case 'preg':
385
            case 'preg_match':
386
            case 'isinrole':
387
            $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...
388
            case 'ir':
389
            case 'memberof':
390
            case 'mo':
391
                // Is Member Of  (same as inrole but this one can be stringed as a conditional)
392
                $this->condition[] = $this->includeMdfFile('memberof');
393
                break;
394
            case 'or':
395
                $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...
396
            case 'and':
397
                $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...
398
            case 'show':
399 View Code Duplication
            case 'this':
400
                $conditional = implode(' ',$this->condition);
401
                $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...
402
                if ($isvalid) return $this->srcValue;
403
                return NULL;
404 View Code Duplication
            case 'then':
405
                $conditional = implode(' ',$this->condition);
406
                $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...
407
                if ($isvalid)  return $opt;
408
                return null;
409 View Code Duplication
            case 'else':
410
                $conditional = implode(' ',$this->condition);
411
                $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...
412
                if (!$isvalid) return $opt;
413
                break;
414
            case 'select':
415
            case 'switch':
416
                $raw = explode('&',$opt);
417
                $map = array();
418
                $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...
419
                for($m=0; $m<$c; $m++) {
420
                    $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...
421
                    $map[$mi[0]] = $mi[1];
422
                }
423
                if(isset($map[$value])) return $map[$value];
424
                else                    return '';
425
            ##### 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...
426
427
            #####  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...
428
            case 'htmlent':
429
            case 'htmlentities':
430
                return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']);
431
            case 'html_entity_decode':
432
            case 'decode_html':
433
            case 'html_decode':
434
                return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']);
435
            case 'esc':
436
            case 'escape':
437
                $value = preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
438
                return str_replace(array('[', ']', '`'),array('&#91;', '&#93;', '&#96;'),$value);
439
            case 'sql_escape':
440
            case 'encode_js':
441
                return $modx->db->escape($value);
442
            case 'htmlspecialchars':
443
            case 'hsc':
444
            case 'encode_html':
445
            case 'html_encode':
446
                return preg_replace('/&amp;(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset']));
447
            case 'spam_protect':
448
                return str_replace(array('@','.'),array('&#64;','&#46;'),$value);
449
            case 'strip':
450
                if($opt==='') $opt = ' ';
451
                return preg_replace('/[\n\r\t\s]+/', $opt, $value);
452
            case 'strip_linefeeds':
453
                return str_replace(array("\n","\r"), '', $value);
454
            case 'notags':
455
            case 'strip_tags':
456
            case 'remove_html':
457
                if($opt!=='')
458
                {
459
                    $param = array();
460
                    foreach(explode(',',$opt) as $v)
461
                    {
462
                        $v = trim($v,'</> ');
463
                        $param[] = "<{$v}>";
464
                    }
465
                    $params = implode(',',$param);
466
                }
467
                else $params = '';
468 View Code Duplication
                if(!strpos($params,'<br>')===false) {
469
                    $value = preg_replace('@(<br[ /]*>)\n@','$1',$value);
470
                    $value = preg_replace('@<br[ /]*>@',"\n",$value);
471
                }
472
                return $this->strip_tags($value,$params);
473
            case 'urlencode':
474
            case 'url_encode':
475
            case 'encode_url':
476
                return urlencode($value);
477
            case 'base64_decode':
478
                if($opt!=='false') $opt = true;
479
                else               $opt = false;
480
                return base64_decode($value,$opt);
481
            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...
482
            case 'addslashes':
483
            case 'urldecode':
484
            case 'url_decode':
485
            case 'rawurlencode':
486
            case 'rawurldecode':
487
            case 'base64_encode':
488
            case 'md5':
489
            case 'sha1':
490
            case 'json_encode':
491
            case 'json_decode':
492
                return $cmd($value);
493
494
            #####  String Modifiers
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
495
            case 'lcase':
496
            case 'strtolower':
497
            case 'lower_case':
498
                return $this->strtolower($value);
499
            case 'ucase':
500
            case 'strtoupper':
501
            case 'upper_case':
502
                return $this->strtoupper($value);
503
            case 'capitalize':
504
                $_ = explode(' ',$value);
505
                foreach($_ as $i=>$v)
506
                {
507
                    $_[$i] = ucfirst($v);
508
                }
509
                return implode(' ',$_);
510 View Code Duplication
            case 'zenhan':
511
                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...
512
                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
513 View Code Duplication
            case 'hanzen':
514
                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...
515
                return mb_convert_kana($value,$opt,$modx->config['modx_charset']);
516
            case 'str_shuffle':
517
            case 'shuffle':
518
                return $this->str_shuffle($value);
519
            case 'reverse':
520
            case 'strrev':
521
                return $this->strrev($value);
522
            case 'length':
523
            case 'len':
524
            case 'strlen':
525
            case 'count_characters':
526
                return $this->strlen($value);
527
            case 'count_words':
528
                $value = trim($value);
529
                return count(preg_split('/\s+/',$value));
530
            case 'str_word_count':
531
            case 'word_count':
532
            case 'wordcount':
533
                return $this->str_word_count($value);
534
            case 'count_paragraphs':
535
                $value = trim($value);
536
                $value = preg_replace('/\r/', '', $value);
537
                return count(preg_split('/\n+/',$value));
538
            case 'strpos':
539
                if($opt!=0&&empty($opt)) return $value;
540
                return $this->strpos($value,$opt);
541
            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...
542
                // default: 70
543
                  $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...
544
                if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap');
545
                else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value);
546
            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...
547
                $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70;
548
                if($modx->config['manager_language']==='japanese-utf8') {
549
                    $chunk = array();
550
                    $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...
551
                    while($bt!=$value) {
552
                        $bt = $value;
553
                        if($this->strlen($value)<$width) {
554
                            $chunk[] = $value;
555
                            break;
556
                        }
557
                        $chunk[] = $this->substr($value,0,$width);
558
                        $value = $this->substr($value,$width);
559
                    }
560
                    return implode("\n",$chunk);
561
                }
562
                else
563
                    return wordwrap($value,$width,"\n",true);
564
            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...
565
                if(empty($opt)) break;
566
                if(strpos($opt,',')!==false) {
567
                    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...
568
                    return $this->substr($value,$b,(int)$e);
569
                }
570
                else return $this->substr($value,$opt);
571
            case 'limit':
572
            case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html
573 View Code Duplication
                if(strpos($opt,'+')!==false)
574
                    list($len,$str) = explode('+',$opt,2);
575
                else {
576
                    $len = $opt;
577
                    $str = '';
578
                }
579
                if($len==='') $len = 100;
580
                if(abs($len) > $this->strlen($value)) $str ='';
581
                if(preg_match('/^[1-9][0-9]*$/',$len)) {
582
                    return $this->substr($value,0,$len) . $str;
583
                }
584
                elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) {
585
                    return $str . $this->substr($value,$len);
586
                }
587
                break;
588
            case 'summary':
589
            case 'smart_description':
590
            case 'smart_desc':
591
                return $this->includeMdfFile('summary');
592
            case 'replace':
593
            case 'str_replace':
594
                if(empty($opt) || strpos($opt,',')===false) break;
595
                if    (substr_count($opt, ',') ==1) $delim = ',';
596
                elseif(substr_count($opt, '|') ==1) $delim = '|';
597
                elseif(substr_count($opt, '=>')==1) $delim = '=>';
598
                elseif(substr_count($opt, '/') ==1) $delim = '/';
599
                else break;
600
                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...
601
                if($value!=='') return str_replace($s,$r,$value);
602
                break;
603
            case 'replace_to':
604
            case 'tpl':
605 View Code Duplication
                if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt);
606
                break;
607
            case 'eachtpl':
608
                $value = explode('||',$value);
609
                $_ = array();
610
                foreach($value as $v) {
611
                    $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt);
612
                }
613
                return implode("\n", $_);
614
            case 'array_pop':
615
            case 'array_shift':
616
                if(strpos($value,'||')!==false) $delim = '||';
617
                else                            $delim = ',';
618
                return $cmd(explode($delim,$value));
619
            case 'preg_replace':
620
            case 'regex_replace':
621
                if(empty($opt) || strpos($opt,',')===false) break;
622
                list($s,$r) = explode(',',$opt,2);
623
                if($value!=='') return preg_replace($s,$r,$value);
624
                break;
625
            case 'cat':
626
            case 'concatenate':
627
            case '.':
628
                if($value!=='') return $value . $opt;
629
                break;
630
            case 'sprintf':
631
            case 'string_format':
632
                if($value!=='') return sprintf($opt,$value);
633
                break;
634
            case 'number_format':
635
                    if($opt=='') $opt = 0;
636
                    return number_format($value,$opt);
637
            case 'money_format':
638
                    setlocale(LC_MONETARY,setlocale(LC_TIME,0));
639
                    if($value!=='') return money_format($opt,(double)$value);
640
                    break;
641
            case 'tobool':
642
                return boolval($value);
643
            case 'nl2lf':
644 View Code Duplication
                if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value);
645
                break;
646
            case 'br2nl':
647
                return preg_replace('@<br[\s/]*>@i', "\n", $value);
648
            case 'nl2br':
649
                if (version_compare(PHP_VERSION, '5.3.0', '<'))
650
                    return nl2br($value);
651
                if($opt!=='')
652
                {
653
                    $opt = trim($opt);
654
                    $opt = strtolower($opt);
655
                    if($opt==='false') $opt = false;
656
                    elseif($opt==='0') $opt = false;
657
                    else               $opt = true;
658
                }
659
                elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html')
660
                                       $opt = false;
661
                else                   $opt = true;
662
                return nl2br($value,$opt);
663
            case 'ltrim':
664
            case 'rtrim':
665
            case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html
666
                if($opt==='')
667
                    return $cmd($value);
668
                else return $cmd($value,$opt);
669
            // These are all straight wrappers for PHP functions
670
            case 'ucfirst':
671
            case 'lcfirst':
672
            case 'ucwords':
673
                return $cmd($value);
674
675
            #####  Date time format
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
676
            case 'strftime':
677
            case 'date':
678
            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...
679
                if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly');
680
                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
681
                if(strpos($opt,'%')!==false)
682
                    return strftime($opt,0+$value);
683
                else
684
                    return date($opt,0+$value);
685
            case 'time':
686
                if(empty($opt)) $opt = '%H:%M';
687
                if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value);
688
                return strftime($opt,0+$value);
689
            case 'strtotime':
690
                return strtotime($value);
691
            #####  mathematical function
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
692
            case 'toint':
693
                return (int)$value;
694
            case 'tofloat':
695
                return floatval($value);
696
            case 'round':
697
                if(!$opt) $opt = 0;
698
                return $cmd($value,$opt);
699
            case 'max':
700
            case 'min':
701
                return $cmd(explode(',',$value));
702
            case 'floor':
703
            case 'ceil':
704
            case 'abs':
705
                return $cmd($value);
706
            case 'math':
707
            case 'calc':
708
                $value = (int)$value;
709
                if(empty($value)) $value = '0';
710
                $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt);
711
                $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter);
712
                if(strpos($filter,'?')===false) $filter = "?{$filter}";
713
                $filter = str_replace('?',$value,$filter);
714
                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...
715
            case 'count':
716
                if($value=='') return 0;
717
                $value = explode(',',$value);
718
                return count($value);
719
            case 'sort':
720
            case 'rsort':
721
                if(strpos($value,"\n")!==false) $delim="\n";
722
                else $delim = ',';
723
                $swap = explode($delim,$value);
724
                if(!$opt) $opt = SORT_REGULAR;
725
                else      $opt = constant($opt);
726
                $cmd($swap,$opt);
727
                return implode($delim,$swap);
728
            #####  Resource fields
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
729
            case 'id':
730
                if($opt) return $this->getDocumentObject($opt,$key);
731
                break;
732
            case 'type':
733
            case 'contenttype':
734
            case 'pagetitle':
735
            case 'longtitle':
736
            case 'description':
737
            case 'alias':
738
            case 'introtext':
739
            case 'link_attributes':
740
            case 'published':
741
            case 'pub_date':
742
            case 'unpub_date':
743
            case 'parent':
744
            case 'isfolder':
745
            case 'content':
746
            case 'richtext':
747
            case 'template':
748
            case 'menuindex':
749
            case 'searchable':
750
            case 'cacheable':
751
            case 'createdby':
752
            case 'createdon':
753
            case 'editedby':
754
            case 'editedon':
755
            case 'deleted':
756
            case 'deletedon':
757
            case 'deletedby':
758
            case 'publishedon':
759
            case 'publishedby':
760
            case 'menutitle':
761
            case 'donthit':
762
            case 'haskeywords':
763
            case 'privateweb':
764
            case 'privatemgr':
765
            case 'content_dispo':
766
            case 'hidemenu':
767
                if($cmd==='contenttype') $cmd = 'contentType';
768
                return $this->getDocumentObject($value,$cmd);
769
            case 'title':
770
                $pagetitle = $this->getDocumentObject($value,'pagetitle');
771
                $longtitle = $this->getDocumentObject($value,'longtitle');
772
                return $longtitle ? $longtitle : $pagetitle;
773
            case 'shorttitle':
774
                $pagetitle = $this->getDocumentObject($value,'pagetitle');
775
                $menutitle = $this->getDocumentObject($value,'menutitle');
776
                return $menutitle ? $menutitle : $pagetitle;
777
            case 'templatename':
778
                $rs = $modx->db->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...
779
                $templateName = $modx->db->getValue($rs);
780
                return !$templateName ? '(blank)' : $templateName;
781
            case 'getfield':
782
                if(!$opt) $opt = 'content';
783
                return $modx->getField($opt,$value);
784
            case 'children':
785
            case 'childids':
786
                if($value=='') $value = 0; // 値がない場合はルートと見なす
787
                $published = 1;
788
                if($opt=='') $opt = 'page';
789
                $_ = explode(',',$opt);
790
                $where = array();
791
                foreach($_ as $opt) {
792
                    switch(trim($opt)) {
793
                        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...
794
                        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...
795
                        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...
796
                        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...
797
                        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...
798
                        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...
799
                    }
800
                }
801
                $where = implode(' AND ', $where);
802
                $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where);
803
                $result = array();
804
                foreach((array)$children as $child){
805
                    $result[] = $child['id'];
806
                }
807
                return implode(',', $result);
808
            case 'fullurl':
809
                if(!is_numeric($value)) return $value;
810
                return $modx->makeUrl($value);
811
            case 'makeurl':
812
                if(!is_numeric($value)) return $value;
813
                if(!$opt) $opt = 'full';
814
                return $modx->makeUrl($value,'','',$opt);
815
816
            #####  File system
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
817
            case 'getimageinfo':
818
            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...
819
                if(!is_file($value)) return '';
820
                $_ = getimagesize($value);
821
                if(!$_[0]) return '';
822
                $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...
823
                $info['height'] = $_[1];
824
                if    ($_[0] > $_[1]) $info['aspect'] = 'landscape';
825
                elseif($_[0] < $_[1]) $info['aspect'] = 'portrait';
826
                else                  $info['aspect'] = 'square';
827
                switch($_[2]) {
828
                    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...
829
                    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...
830
                    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...
831
                    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...
832
                }
833
                $info['attrib'] = $_[3];
834
                switch($opt) {
835
                    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...
836
                    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...
837
                    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...
838
                    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...
839
                    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...
840
                    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...
841
                }
842
843
            case 'file_get_contents':
844
            case 'readfile':
845
                if(!is_file($value)) return $value;
846
                $value = realpath($value);
847
                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...
848
                $ext = strtolower(substr($value,-4));
849
                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...
850
                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...
851
                return file_get_contents($value);
852
            case 'filesize':
853
                if($value == '') return '';
854
                $filename = $value;
855
856
                $site_url = $modx->config['site_url'];
857
                if(strpos($filename,$site_url) === 0)
858
                    $filename = substr($filename,0,strlen($site_url));
859
                $filename = trim($filename,'/');
860
861
                $opt = trim($opt,'/');
862
                if($opt!=='') $opt .= '/';
863
864
                $filename = MODX_BASE_PATH.$opt.$filename;
865
866
                if(is_file($filename)){
867
                    clearstatcache();
868
                    $size = filesize($filename);
869
                    return $size;
870
                }
871
                else return '';
872
            #####  User info
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
873
            case 'username':
874
            case 'fullname':
875
            case 'role':
876
            case 'email':
877
            case 'phone':
878
            case 'mobilephone':
879
            case 'blocked':
880
            case 'blockeduntil':
881
            case 'blockedafter':
882
            case 'logincount':
883
            case 'lastlogin':
884
            case 'thislogin':
885
            case 'failedlogincount':
886
            case 'dob':
887
            case 'gender':
888
            case 'country':
889
            case 'street':
890
            case 'city':
891
            case 'state':
892
            case 'zip':
893
            case 'fax':
894
            case 'photo':
895
            case 'comment':
896
                $this->opt = $cmd;
897
                return $this->includeMdfFile('moduser');
898
            case 'userinfo':
899
                if(empty($opt)) $this->opt = 'username';
900
                return $this->includeMdfFile('moduser');
901
            case 'webuserinfo':
902
                if(empty($opt)) $this->opt = 'username';
903
                $this->value = -$value;
904
                return $this->includeMdfFile('moduser');
905
            #####  Special functions
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
906
            case 'ifempty':
907
            case '_default':
908
            case 'default':
909
                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...
910
            case 'ifnotempty':
911
                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...
912
            case 'datagrid':
913
                include_once(MODX_CORE_PATH . 'controls/datagrid.class.php');
914
                $grd = new DataGrid(null, trim($value));
915
                $grd->itemStyle = '';
916
                $grd->altItemStyle = '';
917
                $pos = strpos($value,"\n");
918
                if($pos) $_ = substr($value,0,$pos);
919
                else $_ = $pos;
920
                $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ',';
921
                return $grd->render();
922
            case 'rotate':
923
            case 'evenodd':
924
                if(strpos($opt,',')===false) $opt = 'odd,even';
925
                $_ = explode(',', $opt);
926
                $c = count($_);
927
                $i = $value + $c;
928
                $i = $i % $c;
929
                return $_[$i];
930
            case 'takeval':
931
                $arr = explode(",",$opt);
932
                $idx = $value;
933
                if(!is_numeric($idx)) return $value;
934
                return $arr[$idx];
935
            case 'getimage':
936
                return $this->includeMdfFile('getimage');
937
            case 'nicesize':
938
                    return $modx->nicesize($value);
939
            case 'googlemap':
940
            case 'googlemaps':
941
                if(empty($opt)) $opt = 'border:none;width:500px;height:350px;';
942
                $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>';
943
                $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...
944
                $ph['value'] = $value;
945
                return $modx->parseText($tpl,$ph);
946
            case 'youtube':
947
            case 'youtube16x9':
948
                if(empty($opt)) $opt = 560;
949
                $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...
950
                $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>';
951
                return sprintf($tpl,$opt,$h,$value);
952
            //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...
953
            case 'setvar':
954
                $modx->placeholders[$opt] = $value;
955
                return '';
956
            case 'csstohead':
957
                $modx->regClientCSS($value);
958
                return '';
959
            case 'htmltohead':
960
                $modx->regClientStartupHTMLBlock($value);
961
                return '';
962
            case 'htmltobottom':
963
                $modx->regClientHTMLBlock($value);
964
                return '';
965
            case 'jstohead':
966
                $modx->regClientStartupScript($value);
967
                return '';
968
            case 'jstobottom':
969
                $modx->regClientScript($value);
970
                return '';
971
            case 'dummy':
972
                return $value;
973
974
            // If we haven't yet found the modifier, let's look elsewhere
975
            default:
976
                $value = $this->getValueFromElement($key, $value, $cmd, $opt);
977
        }
978
        return $value;
979
    }
980
981
    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...
982
        $modx = evolutionCMS();
983
        $key = $this->key;
984
        $value  = $this->value;
985
        $opt    = $this->opt;
986
        return include(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php");
987
    }
988
989
    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...
990
    {
991
        $modx = evolutionCMS();
992
        if( isset($modx->snippetCache[$this->elmName]) )
993
        {
994
            $php = $modx->snippetCache[$this->elmName];
995
        }
996
        else
997
        {
998
            $esc_elmName = $modx->db->escape($this->elmName);
999
            $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'");
1000
            $total = $modx->db->getRecordCount($result);
1001
            if($total == 1)
1002
            {
1003
                $row = $modx->db->getRow($result);
1004
                $php = $row['snippet'];
1005
            }
1006
            elseif($total == 0)
1007
            {
1008
                $assets_path = MODX_BASE_PATH.'assets/';
1009
                if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php"))
1010
                    $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php";
1011
                elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php"))
1012
                    $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php";
1013
                elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"))
1014
                    $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php";
1015
                else $modifiers_path = false;
1016
1017
                if($modifiers_path !== false) {
1018
                    $php = @file_get_contents($modifiers_path);
1019
                    $php = trim($php);
1020
                    if(substr($php,0,5)==='<?php') $php = substr($php,6);
1021
                    if(substr($php,0,2)==='<?')    $php = substr($php,3);
1022
                    if(substr($php,-2)==='?>')     $php = substr($php,0,-2);
1023
                    if($this->elmName!=='')
1024
                        $modx->snippetCache[$this->elmName.'Props'] = '';
1025
                }
1026
                else
1027
                    $php = false;
1028
            }
1029
            else $php = false;
1030
            if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php;
1031
        }
1032
        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...
1033
1034
        if($php===false) $html = $modx->getChunk($this->elmName);
1035
        else             $html = false;
1036
1037
        $self = '[+output+]';
1038
1039
        if($php !== false)
1040
        {
1041
            ob_start();
1042
            $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...
1043
            $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...
1044
            $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...
1045
            $this->bt = $value;
1046
            $this->vars['value']   = & $value;
1047
            $this->vars['input']   = & $value;
1048
            $this->vars['option']  = & $opt;
1049
            $this->vars['options'] = & $opt;
1050
            $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...
1051
            $msg = ob_get_contents();
1052
            if($value===$this->bt) $value = $msg . $custom;
1053
            ob_end_clean();
1054
        }
1055
        elseif($html!==false && isset($value) && $value!=='')
1056
        {
1057
            $html = str_replace(array($self,'[+value+]'), $value, $html);
1058
            $value = str_replace(array('[+options+]','[+param+]'), $opt, $html);
1059
        }
1060
        else return false;
1061
1062
        if($php===false && $html===false && $value!==''
1063
           && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false))
1064
        {
1065
            $value = str_replace(array('[+value+]',$self),$value,$cmd);
1066
        }
1067
        return $value;
1068
    }
1069
1070
    public function parseDocumentSource($content='')
1071
    {
1072
        $modx = evolutionCMS();
1073
1074
        if(strpos($content,'[')===false && strpos($content,'{')===false) return $content;
1075
1076
        if(!$modx->maxParserPasses) $modx->maxParserPasses = 10;
1077
        $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...
1078
        $i=0;
1079
        while($bt!==$content)
1080
        {
1081
            $bt = $content;
1082
            if(strpos($content,'[*')!==false && $modx->documentIdentifier)
1083
                                              $content = $modx->mergeDocumentContent($content);
1084
            if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content);
1085
            if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content);
1086
            if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content);
1087
            if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content);
1088
1089
            if($content===$bt)              break;
1090
            if($modx->maxParserPasses < $i) break;
1091
            $i++;
1092
        }
1093
        return $content;
1094
    }
1095
1096
    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...
1097
    {
1098
        $modx = evolutionCMS();
1099
1100
        $target = trim($target);
1101
        if(empty($target)) $target = $modx->config['site_start'];
1102
        if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id';
1103
        else $method = 'alias';
1104
1105
        if(!isset($this->documentObject[$target]))
1106
        {
1107
            $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct');
1108
        }
1109
1110
        if($this->documentObject[$target]['publishedon']==='0')
1111
            return '';
1112
        elseif(isset($this->documentObject[$target][$field]))
1113
        {
1114
            if(is_array($this->documentObject[$target][$field]))
1115
            {
1116
                $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...
1117
                $this->documentObject[$target][$field] = $a[$field];
1118
            }
1119
        }
1120
        else $this->documentObject[$target][$field] = false;
1121
1122
        return $this->documentObject[$target][$field];
1123
    }
1124
1125
    public function setPlaceholders($value = '', $key = '', $path = '') {
1126
        if($path!=='') $key = "{$path}.{$key}";
1127
        if (is_array($value)) {
1128
            foreach ($value as $subkey => $subval) {
1129
                $this->setPlaceholders($subval, $subkey, $key);
1130
            }
1131
        }
1132
        else $this->setModifiersVariable($key, $value);
1133
    }
1134
1135
    // Sets a placeholder variable which can only be access by Modifiers
1136
    public function setModifiersVariable($key, $value) {
1137
        if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value;
1138
    }
1139
1140
    //mbstring
1141
    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...
1142
        $modx = evolutionCMS();
1143
        if(is_null($l)) $l = $this->strlen($str);
1144
        if (function_exists('mb_substr'))
1145
        {
1146
            if(strpos($str,"\r")!==false)
1147
                $str = str_replace(array("\r\n","\r"), "\n", $str);
1148
            return mb_substr($str, $s, $l, $modx->config['modx_charset']);
1149
        }
1150
        return substr($str, $s, $l);
1151
    }
1152
    public function strpos($haystack,$needle,$offset=0) {
1153
        $modx = evolutionCMS();
1154
        if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']);
1155
        return strpos($haystack,$needle,$offset);
1156
    }
1157
    public function strlen($str) {
1158
        $modx = evolutionCMS();
1159
        if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']);
1160
        return strlen($str);
1161
    }
1162
    public function strtolower($str) {
1163
        if (function_exists('mb_strtolower')) return mb_strtolower($str);
1164
        return strtolower($str);
1165
    }
1166
    public function strtoupper($str) {
1167
        if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
1168
        return strtoupper($str);
1169
    }
1170
    public function ucfirst($str) {
1171
        if (function_exists('mb_strtoupper'))
1172
            return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1173
        return ucfirst($str);
1174
    }
1175
    public function lcfirst($str) {
1176
        if (function_exists('mb_strtolower'))
1177
            return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str));
1178
        return lcfirst($str);
1179
    }
1180
    public function ucwords($str) {
1181
        if (function_exists('mb_convert_case'))
1182
            return mb_convert_case($str, MB_CASE_TITLE);
1183
        return ucwords($str);
1184
    }
1185
    public function strrev($str) {
1186
        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...
1187
        return implode(array_reverse($ar[0]));
1188
    }
1189
    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...
1190
        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...
1191
        shuffle($ar[0]);
1192
        return implode($ar[0]);
1193
    }
1194
    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...
1195
        return count(preg_split('~[^\p{L}\p{N}\']+~u',$str));
1196
    }
1197
    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...
1198
        $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...
1199
1200 View Code Duplication
        if(stripos($params,'style')===false && stripos($value,'</style>')!==false) {
1201
            $value = preg_replace('@<style.*?>.*?</style>@is', '', $value);
1202
        }
1203 View Code Duplication
        if(stripos($params,'script')===false && stripos($value,'</script>')!==false) {
1204
            $value = preg_replace('@<script.*?>.*?</script>@is', '', $value);
1205
        }
1206
1207
        return trim(strip_tags($value,$params));
1208
    }
1209
}
1210