ValidationHelper::validateModuleName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace SilverStripe\Porter\Helpers;
4
5
use Symfony\Component\Yaml\Exception\RuntimeException;
6
7
/**
8
 * Class ValidationHelper
9
 */
10
class ValidationHelper
11
{
12
    /**
13
     * Validates the format of the given namespace
14
     * @param $namespace
15
     * @return bool
16
     * @throws RuntimeException
17
     */
18
    public static function validateNamespace($namespace)
19
    {
20
        if (in_array(substr_count($namespace, '\\'), [0, 1])) {
21
            $message = "It seems your namespace is formed incorrectly.\n"
22
                . "Possible examples are NameSpace\\\\ or NameSpace\\\\Folder\\\\\n"
23
                . "[Double backslashes]";
24
            throw new RuntimeException($message);
25
        }
26
27
        return true;
28
    }
29
30
    /**
31
     * Validates the format of the given module name
32
     * @param $moduleName
33
     * @return bool
34
     * @throws RuntimeException
35
     */
36
    public static function validateModuleName($moduleName)
37
    {
38
        if (stripos($moduleName, DIRECTORY_SEPARATOR) === false) {
39
            throw new RuntimeException('Invalid module name given. Use the format module/name');
40
        }
41
42
        return true;
43
    }
44
}
45