Validator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B isGitUrl() 0 23 4
A areStandardsValid() 0 10 3
1
<?php
2
3
namespace SnifferReport\Service;
4
5
use \PHP_CodeSniffer;
6
7
abstract class Validator
8
{
9
10
    /**
11
     * Checks if a given url is a valid Git url.
12
     *
13
     * @param $url
14
     *   The URL to be checked.
15
     *
16
     * @return bool
17
     *   Whether the given URL is valid or not.
18
     */
19
    public static function isGitUrl($url)
20
    {
21
        if (!$url) {
22
            return false;
23
        }
24
25
        // @todo: change validation to accept any git url.
26
        $patterns = array(
27
            '#git.drupal.org/project#',
28
            '#git.drupal.org/sandbox#',
29
            '#github.com#',
30
        );
31
32
        $valid = false;
33
        foreach ($patterns as $pattern) {
34
            if (preg_match($pattern, $url)) {
35
                $valid = true;
36
                break;
37
            }
38
        }
39
40
        return $valid;
41
    }
42
43
    /**
44
     * Checks if given standards are supported by the application.
45
     *
46
     * @param array $standards
47
     *   The standards to be validated
48
     *
49
     * @return bool
50
     *   Whether the given standards are valid or not.
51
     */
52
    public static function areStandardsValid(array $standards)
53
    {
54
        foreach ($standards as $standard) {
55
            if (!in_array($standard, PHP_CodeSniffer::getInstalledStandards())) {
56
                return false;
57
            }
58
        }
59
60
        return true;
61
    }
62
}
63