Passed
Push — master ( 1f6f72...a5203b )
by Tom
02:42
created

ReferenceTypes   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 49
ccs 8
cts 8
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidId() 0 3 1
A isSection() 0 3 2
A isPatternSection() 0 3 2
A getSections() 0 3 1
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File;
6
7
/**
8
 * Class References
9
 *
10
 * Utility class for pipeline references (ids) definition and validation
11
 *
12
 * pipeline        : that what can be referenced (id): default, branches/**, custom/foo etc.
13
 * section         : branches, tags, bookmarks, pull-requests, custom
14
 * pattern section : a section that can match by pattern to some input (all sections but custom)
15
 *
16
 * @package Ktomk\Pipelines\File
17
 */
18
class ReferenceTypes
19
{
20
    /**
21
     * pipelines sections on first level that contain pipelines on second level
22
     *
23
     * @var array
24
     */
25
    private static $sections = array('branches', 'tags', 'bookmarks', 'pull-requests', 'custom');
26
27
    /**
28
     * @param string $id
29
     *
30
     * @return bool
31
     */
32 7
    public static function isValidId($id)
33
    {
34 7
        return (bool)preg_match('~^(default|(' . implode('|', self::$sections) . ')/[^\x00-\x1F\x7F-\xFF]*)$~', $id);
35
    }
36
37
    /**
38
     * a section that contains pipelines that can match by pattern
39
     *
40
     * @param null|int|string $section
41
     *
42
     * @return bool
43
     */
44 9
    public static function isPatternSection($section)
45
    {
46 9
        return is_string($section) && \in_array($section, array_slice(self::$sections, 0, 4), true);
47
    }
48
49
    /**
50
     * @param null|int|string $section
51
     *
52
     * @return bool
53
     */
54 9
    public static function isSection($section)
55
    {
56 9
        return is_string($section) && in_array($section, self::$sections, true);
57
    }
58
59
    /**
60
     * get sections
61
     *
62
     * @return array|string[]
63
     */
64 1
    public static function getSections()
65
    {
66 1
        return self::$sections;
67
    }
68
}
69