PluginReverse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 16 4
1
<?php
2
/**
3
 * Copyright (c) 2013-2017
4
 *
5
 * @category  Library
6
 * @package   Dwoo\Plugins\Functions
7
 * @author    Jordi Boggiano <[email protected]>
8
 * @author    David Sanchez <[email protected]>
9
 * @copyright 2008-2013 Jordi Boggiano
10
 * @copyright 2013-2017 David Sanchez
11
 * @license   http://dwoo.org/LICENSE Modified BSD License
12
 * @version   1.3.2
13
 * @date      2017-01-06
14
 * @link      http://dwoo.org/
15
 */
16
17
namespace Dwoo\Plugins\Functions;
18
19
use Dwoo\Plugin;
20
21
/**
22
 * Reverses a string or an array
23
 * <pre>
24
 *  * value : the string or array to reverse
25
 *  * preserve_keys : if value is an array and this is true, then the array keys are left intact
26
 * </pre>
27
 * This software is provided 'as-is', without any express or implied warranty.
28
 * In no event will the authors be held liable for any damages arising from the use of this software.
29
 */
30
class PluginReverse extends Plugin
31
{
32
    /**
33
     * @param string $value
34
     * @param bool   $preserve_keys
35
     *
36
     * @return array|string
37
     */
38
    public function process($value, $preserve_keys = false)
39
    {
40
        if (is_array($value)) {
41
            return array_reverse($value, $preserve_keys);
42
        } elseif (($charset = $this->core->getCharset()) === 'iso-8859-1') {
43
            return strrev((string)$value);
44
        }
45
46
        $strlen = mb_strlen($value);
47
        $out    = '';
48
        while ($strlen --) {
49
            $out .= mb_substr($value, $strlen, 1, $charset);
50
        }
51
52
        return $out;
53
    }
54
}