Passed
Push — master ( 2b9d5b...cc8c81 )
by Alex
48s
created

TPropertyTypeTrait::isTPropertyTypeValid()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 26
rs 8.439
c 2
b 0
f 0
cc 5
eloc 15
nc 5
nop 1
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\MetadataV3\edm\IsOKTraits;
4
5
trait TPropertyTypeTrait
6
{
7
    use EDMSimpleTypeTrait, TQualifiedNameTrait;
8
9
    protected static $v3PropertyTypeCache = [];
10
    protected static $v3PropertyTypeRegex =
11
        "/[\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,}/";
12
13
    public function isTPropertyTypeValid($string)
14
    {
15
        //The below pattern represents the allowed identifiers in ECMA specification
16
        // plus the '.' for namespace qualification
17
        //$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,}/";
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
18
19
        if (!is_string($string)) {
20
            $msg = "Input must be a string: " . get_class($this);
21
            throw new \InvalidArgumentException($msg);
22
        }
23
        if (isset(static::$v3PropertyTypeCache[$string])) {
24
            return static::$v3PropertyTypeCache[$string];
25
        }
26
27
        if ($this->isEDMSimpleTypeValid($string)) {
28
            static::$v3PropertyTypeCache[$string] = true;
29
            return true;
30
        }
31
        if ($this->isTQualifiedNameValid($string)) {
32
            static::$v3PropertyTypeCache[$string] = true;
33
            return true;
34
        }
35
        $result = $this->matchesRegexPattern(static::$v3PropertyTypeRegex, $string);
36
        static::$v3PropertyTypeCache[$string] = $result;
37
        return $result;
38
    }
39
}
40