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.
Completed
Pull Request — develop (#322)
by
unknown
01:56
created

ord.php ➔ utf8_ord()   C

Complexity

Conditions 20
Paths 13

Size

Total Lines 75
Code Lines 51

Duplication

Lines 19
Ratio 25.33 %

Importance

Changes 0
Metric Value
cc 20
eloc 51
nc 13
nop 1
dl 19
loc 75
rs 5.2663
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
* @package utf8
4
*/
5
6
//---------------------------------------------------------------
7
/**
8
* UTF-8 aware alternative to ord
9
* Returns the unicode ordinal for a character
10
* @param string UTF-8 encoded character
11
* @return int unicode ordinal for the character
12
* @see http://www.php.net/ord
13
* @see http://www.php.net/manual/en/function.ord.php#46267
14
*/
15
function utf8_ord($chr) {
16
17
    $ord0 = ord($chr);
18
19
    if ( $ord0 >= 0 && $ord0 <= 127 ) {
20
        return $ord0;
21
    }
22
23
    if ( !isset($chr{1}) ) {
24
        trigger_error('Short sequence - at least 2 bytes expected, only 1 seen');
25
        return FALSE;
26
    }
27
28
    $ord1 = ord($chr{1});
29
    if ( $ord0 >= 192 && $ord0 <= 223 ) {
30
        return ( $ord0 - 192 ) * 64
31
            + ( $ord1 - 128 );
32
    }
33
34
    if ( !isset($chr{2}) ) {
35
        trigger_error('Short sequence - at least 3 bytes expected, only 2 seen');
36
        return FALSE;
37
    }
38
    $ord2 = ord($chr{2});
39 View Code Duplication
    if ( $ord0 >= 224 && $ord0 <= 239 ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
        return ($ord0-224)*4096
41
            + ($ord1-128)*64
42
                + ($ord2-128);
43
    }
44
45
    if ( !isset($chr{3}) ) {
46
        trigger_error('Short sequence - at least 4 bytes expected, only 3 seen');
47
        return FALSE;
48
    }
49
    $ord3 = ord($chr{3});
50 View Code Duplication
    if ($ord0>=240 && $ord0<=247) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
        return ($ord0-240)*262144
52
            + ($ord1-128)*4096
53
                + ($ord2-128)*64
54
                    + ($ord3-128);
55
56
    }
57
58
    if ( !isset($chr{4}) ) {
59
        trigger_error('Short sequence - at least 5 bytes expected, only 4 seen');
60
        return FALSE;
61
    }
62
    $ord4 = ord($chr{4});
63 View Code Duplication
    if ($ord0>=248 && $ord0<=251) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
        return ($ord0-248)*16777216
65
            + ($ord1-128)*262144
66
                + ($ord2-128)*4096
67
                    + ($ord3-128)*64
68
                        + ($ord4-128);
69
    }
70
71
    if ( !isset($chr{5}) ) {
72
        trigger_error('Short sequence - at least 6 bytes expected, only 5 seen');
73
        return FALSE;
74
    }
75
    if ($ord0>=252 && $ord0<=253) {
76
        return ($ord0-252) * 1073741824
77
            + ($ord1-128)*16777216
78
                + ($ord2-128)*262144
79
                    + ($ord3-128)*4096
80
                        + ($ord4-128)*64
81
                            + (ord($chr{5})-128);
82
    }
83
84
    if ( $ord0 >= 254 && $ord0 <= 255 ) {
85
        trigger_error('Invalid UTF-8 with surrogate ordinal '.$ord0);
86
        return FALSE;
87
    }
88
89
}
90
91