Completed
Push — develop ( d568f8...c061fc )
by Agel_Nash
06:25
created

MODIFIERS::_getOpt()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1430
    {
1431
        if (function_exists('mb_strtoupper')) {
1432
            return mb_strtoupper($this->substr($str, 0, 1)) . $this->substr($str, 1, $this->strlen($str));
1433
        }
1434
        return ucfirst($str);
1435
    }
1436 View Code Duplication
    public function lcfirst($str)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1437
    {
1438
        if (function_exists('mb_strtolower')) {
1439
            return mb_strtolower($this->substr($str, 0, 1)) . $this->substr($str, 1, $this->strlen($str));
1440
        }
1441
        return lcfirst($str);
1442
    }
1443
    public function ucwords($str)
1444
    {
1445
        if (function_exists('mb_convert_case')) {
1446
            return mb_convert_case($str, MB_CASE_TITLE);
1447
        }
1448
        return ucwords($str);
1449
    }
1450
    public function strrev($str)
1451
    {
1452
        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...
1453
        return implode(array_reverse($ar[0]));
1454
    }
1455
    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...
1456
    {
1457
        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...
1458
        shuffle($ar[0]);
1459
        return implode($ar[0]);
1460
    }
1461
    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...
1462
    {
1463
        return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
1464
    }
1465
    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...
1466
    {
1467
        $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...
1468
1469 View Code Duplication
        if (stripos($params, 'style')===false && stripos($value, '</style>')!==false) {
1470
            $value = preg_replace('@<style.*?>.*?</style>@is', '', $value);
1471
        }
1472 View Code Duplication
        if (stripos($params, 'script')===false && stripos($value, '</script>')!==false) {
1473
            $value = preg_replace('@<script.*?>.*?</script>@is', '', $value);
1474
        }
1475
1476
        return trim(strip_tags($value, $params));
1477
    }
1478
}
1479