Passed
Branch ignore-files (1e3f4a)
by Natan
02:30
created

Validator::isGitUrl()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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