Completed
Push — master ( 48cc3d...5640fa )
by Craig
12:32 queued 05:19
created

SanitizeHelper::sanitizeController()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 14
rs 9.4285
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.4 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Helper;
14
15
/**
16
 * Helper class for sanitizing route properties.
17
 */
18
class SanitizeHelper
19
{
20
    /**
21
     * Sanitizes the controller / type parameter.
22
     *
23
     * @param string $controllerName
24
     *
25
     * @return array [$controllerName, $type]
26
     */
27
    public function sanitizeController($controllerName)
28
    {
29
        if (substr($controllerName, -10) !== 'Controller') {
30
            $type = $controllerName;
31
            $controllerName .= 'Controller';
32
        } else {
33
            $type = substr($controllerName, 0, -10);
34
        }
35
36
        $type = strtolower($type);
37
        $controllerName = ucfirst($controllerName);
38
39
        return [$controllerName, $type];
40
    }
41
42
    /**
43
     * Sanitizes the action / func parameter.
44
     *
45
     * @param string $methodName
46
     *
47
     * @return array [$methodName, $func]
48
     */
49
    public function sanitizeAction($methodName)
50
    {
51
        if (substr($methodName, -6) !== 'Action') {
52
            $methodName .= 'Action';
53
        }
54
55
        $methodName = ucfirst($methodName);
56
        $func = lcfirst(substr($methodName, 0, -6));
57
58
        return [$methodName, $func];
59
    }
60
}
61