Passed
Push — master ( cc8c81...f0282f )
by Christopher
04:33
created

TPropertyTypeTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isTPropertyTypeValid() 0 18 4
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\MetadataV3\edm\IsOKTraits;
4
5
trait TPropertyTypeTrait
6
{
7
    use EDMSimpleTypeTrait, TQualifiedNameTrait;
8
9
    public function isTPropertyTypeValid($string)
10
    {
11
        //The below pattern represents the allowed identifiers in ECMA specification
12
        // plus the '.' for namespace qualification
13
        $regex = "/[\p{L}\p{Nl}][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}(\.[\p{L}\p{Nl}][\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Pc}\p{Cf}]{0,}){0,}/";
14
15
        if (!is_string($string)) {
16
            $msg = "Input must be a string: ". get_class($this);
17
            throw new \InvalidArgumentException($msg);
18
        }
19
        if ($this->isEDMSimpleTypeValid($string)) {
20
            return true;
21
        }
22
        if ($this->isTQualifiedNameValid($string)) {
23
            return true;
24
        }
25
        return $this->matchesRegexPattern($regex, $string);
26
    }
27
}
28