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

TPropertyTypeTrait::isTPropertyTypeValid()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.2
cc 4
eloc 10
nc 4
nop 1
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