Passed
Push — master ( 26efa5...f69765 )
by Alex
03:20
created

xsdRestrictions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isNCName() 0 4 2
A isName() 0 4 1
A matchesRegexPattern() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Doc
5
 * Date: 4/30/2017
6
 * Time: 1:29 PM
7
 */
8
9
namespace AlgoWeb\ODataMetadata;
10
11
/**
12
 * trait xsdRestrictions
13
 * @package AlgoWeb\ODataMetadata
14
 */
15
trait xsdRestrictions
16
{
17
    /**
18
     * Checks if it is a valid NCName
19
     *
20
     * <xsd:simpleType name="NCName" id="NCName">
21
     *     <xsd:restriction base="xsd:Name">
22
     *         <xsd:pattern value="[\i-[:]][\c-[:]]*"/>
23
     *     </xsd:restriction>
24
     * </xsd:simpleType>
25
     *
26
     * @param string $string the string to check
27
     * @return bool if it is valid
28
     */
29
    protected function isNCName($string)
30
    {
31
        return $this->matchesRegexPattern("[\i-[:]][\c-[:]]*", $string) && $this->isName($string);
32
    }
33
34
    /**
35
     * Checks a pattern against a string
36
     * @param string $pattern the regex pattern
37
     * @param string $string the string to check
38
     * @return bool true if string matches pattern
39
     */
40
    protected function matchesRegexPattern($pattern, $string)
0 ignored issues
show
Unused Code introduced by
The parameter $pattern is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
        return (preg_match("\i\c*", $string) == 1);
43
    }
44
45
    /**
46
     * Checks if is ivalid Name
47
     *
48
     *
49
     * <xsd:simpleType name="Name" id="Name">
50
     *     <xsd:restriction base="xsd:token">
51
     *         <xsd:pattern value="\i\c*"/>
52
     *     </xsd:restriction>
53
     * </xsd:simpleType>
54
     *
55
     * @param string $string the string to check
56
     * @return bool  if it is valid
57
     */
58
    protected function isName($string)
59
    {
60
        return $this->matchesRegexPattern("\i\c*", $string);
61
    }
62
}
63