GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RegexBuilder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addCodepoint() 0 4 1
A flattenCodepoint() 0 4 1
A addRange() 0 4 1
A flattenRange() 0 11 2
A getCharacterClass() 0 6 2
1
<?php
2
3
namespace UCD\Unicode\Codepoint;
4
5
use UCD\Unicode\Codepoint;
6
use UCD\Unicode\Codepoint\Range;
7
use UCD\Unicode\RegexProvider;
8
9
class RegexBuilder implements RegexProvider
10
{
11
    /**
12
     * @var string
13
     */
14
    private $regex;
15
16
    /**
17
     * @param Codepoint $codepoint
18
     */
19
    public function addCodepoint(Codepoint $codepoint)
20
    {
21
        $this->regex .= $this->flattenCodepoint($codepoint);
22
    }
23
24
    /**
25
     * @param Codepoint $codepoint
26
     * @return string
27
     */
28
    private function flattenCodepoint(Codepoint $codepoint)
29
    {
30
        return sprintf('\x{%X}', $codepoint->getValue());
31
    }
32
33
    /**
34
     * @param Range $range
35
     */
36
    public function addRange(Range $range)
37
    {
38
        $this->regex .= $this->flattenRange($range);
39
    }
40
41
    /**
42
     * @param Range $range
43
     * @return string
44
     */
45
    private function flattenRange(Range $range)
46
    {
47
        if ($range->representsSingleCodepoint()) {
48
            return $this->flattenCodepoint($range->getStart());
49
        }
50
51
        $start = $range->getStart();
52
        $end = $range->getEnd();
53
54
        return sprintf('\x{%X}-\x{%X}', $start->getValue(), $end->getValue());
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getCharacterClass()
61
    {
62
        return $this->regex !== null
63
            ? sprintf('[%s]', $this->regex)
64
            : '';
65
    }
66
}