Passed
Push — master ( 2d4076...4300fd )
by Christopher
03:19
created

xsdRestrictions.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 $pattern string 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
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
}