ValidationHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateNamespace() 0 11 2
A validateModuleName() 0 8 2
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