Completed
Push — master ( 819155...51529b )
by Alex
04:17
created

TSimpleIdentifierTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isTSimpleIdentifierValid() 0 24 4
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\MetadataV3\edm\IsOKTraits;
4
5
use AlgoWeb\ODataMetadata\xsdRestrictions;
6
7
trait TSimpleIdentifierTrait
8
{
9
    use xsdRestrictions;
10
11
    public function isTSimpleIdentifierValid($string)
12
    {
13
        //The below pattern represents the allowed identifiers in ECMA specification
14
        /*
15
         * Match a single character present in the list below [\p{L}\p{Nl}]
16
         * \p{L} matches any kind of letter from any language
17
         * \p{Nl} matches a number that looks like a letter, such as a Roman numeral
18
         * Match a single character present in the list below [\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}
19
         * {0,} Quantifier — Matches between zero and unlimited times, as many times as possible,
20
         * giving back as needed (greedy)
21
         * \p{L} matches any kind of letter from any language
22
         * \p{Nl} matches a number that looks like a letter, such as a Roman numeral
23
         * \p{Nd} matches a digit zero through nine in any script except ideographic scripts
24
         * \p{Mn} matches a character intended to be combined with another character without taking up extra space
25
         * (e.g. accents, umlauts, etc.)
26
         * \p{Mc} matches a character intended to be combined with another character that takes up extra space
27
         * (vowel signs in many Eastern languages)
28
         * \p{Pc} matches a punctuation character such as an underscore that connects words
29
         * \p{Cf} matches invisible formatting indicator
30
         */
31
        $regex = '/[\p{L}\p{Nl}][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}/';
32
        return is_string($string) && (trim($string) == $string) && 480 >= strlen($string)
33
               && $this->matchesRegexPattern($regex, $string);
34
    }
35
}
36