Test Failed
Push — master ( b697ab...976fd4 )
by Bálint
01:43 queued 16s
created

Char::convertToOData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace POData\Providers\Metadata\Type;
4
5
use POData\Common\NotImplementedException;
6
7
/**
8
 * Class Char
9
 * @package POData\Providers\Metadata\Type
10
 */
11
class Char implements IType
12
{
13
    const A = 65;
14
    const Z = 90;
15
    const SMALL_A = 97;
16
    const SMALL_Z = 122;
17
    const F = 70;
18
    const SMALL_F = 102;
19
    const ZERO = 48;
20
    const NINE = 57;
21
    const TAB = 9;
22
    const NEWLINE = 10;
23
    const CARRIAGE_RETURN = 13;
24
    const SPACE = 32;
25
    
26
    /**
27
     * Gets the type code
28
     * Note: implementation of IType::getTypeCode
29
     *   
30
     * @return TypeCode
31
     */
32
    public function getTypeCode()
33
    {
34
        return TypeCode::CHAR;
0 ignored issues
show
Bug Best Practice introduced by
The expression return POData\Providers\...ata\Type\TypeCode::CHAR returns the type integer which is incompatible with the documented return type POData\Providers\Metadata\Type\TypeCode.
Loading history...
35
    }
36
37
    /**
38
     * Checks this type is compatible with another type
39
     * Note: implementation of IType::isCompatibleWith
40
     * 
41
     * @param IType $type Type to check compatibility
42
     * 
43
     * @return boolean 
44
     */
45
    public function isCompatibleWith(IType $type)
46
    {
47
        switch ($type->getTypeCode()) {
48
            case TypeCode::BYTE:
49
            case TypeCode::CHAR:
50
                return true;
51
        }
52
        
53
        return false;
54
    }
55
56
    /**
57
     * Validate a value in Astoria uri is in a format for this type
58
     * Note: implementation of IType::validate
59
     * 
60
     * @param string $value     The value to validate 
61
     * @param string &$outValue The stripped form of $value that can 
62
     *                          be used in PHP expressions
63
     * 
64
     * @return boolean
65
     */
66
    public function validate($value, &$outValue)
67
    {
68
        //No EDM Char primitive type
69
        throw new NotImplementedException();
70
    }
71
72
    /**
73
     * Gets full name of this type in EDM namespace
74
     * Note: implementation of IType::getFullTypeName
75
     * 
76
     * @return string
77
     */
78
    public function getFullTypeName()
79
    {
80
        return 'System.Char';
81
    }
82
83
    /**
84
     * Converts the given string value to char type.     
85
     * Note: This function will not perform any conversion.
86
     * 
87
     * @param string $stringValue The value to convert.
88
     * 
89
     * @return string
90
     */
91
    public function convert($stringValue)
92
    {
93
        return $stringValue;     
94
    }
95
96
    /**
97
     * Convert the given value to a form that can be used in OData uri.
98
     * Note: The calling function should not pass null value, as this 
99
     * function will not perform any check for nullability 
100
     * 
101
     * @param mixed $value The value to convert.
102
     * 
103
     * @return string
104
     */
105
    public function convertToOData($value)
106
    {
107
        return $value;
108
    }
109
110
    /**
111
     * Checks a character is whilespace
112
     * 
113
     * @param char $char character to check
114
     * 
115
     * @return boolean
116
     */
117
    public static function isWhiteSpace($char)
118
    {
119
        $asciiVal = ord($char);
0 ignored issues
show
Bug introduced by
$char of type POData\Providers\Metadata\Type\char is incompatible with the type string expected by parameter $character of ord(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

119
        $asciiVal = ord(/** @scrutinizer ignore-type */ $char);
Loading history...
120
        return $asciiVal == Char::SPACE 
121
            || $asciiVal == Char::TAB 
122
            || $asciiVal == Char::CARRIAGE_RETURN 
123
            || $asciiVal == Char::NEWLINE;
124
    }
125
126
    /**
127
     * Checks a character is letter 
128
     * 
129
     * @param char $char character to check
130
     * 
131
     * @return boolean
132
     */
133
    public static function isLetter($char)
134
    {
135
        $asciiVal = ord($char);
0 ignored issues
show
Bug introduced by
$char of type POData\Providers\Metadata\Type\char is incompatible with the type string expected by parameter $character of ord(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

135
        $asciiVal = ord(/** @scrutinizer ignore-type */ $char);
Loading history...
136
        return ($asciiVal >= Char::A && $asciiVal <= Char::Z) 
137
            || ($asciiVal >= Char::SMALL_A && $asciiVal <= Char::SMALL_Z);
138
    }
139
140
    /**
141
     * Checks a character is digit 
142
     * 
143
     * @param char $char character to check
144
     * 
145
     * @return boolean
146
     */
147
    public static function isDigit($char)
148
    {
149
        $asciiVal = ord($char);
0 ignored issues
show
Bug introduced by
$char of type POData\Providers\Metadata\Type\char is incompatible with the type string expected by parameter $character of ord(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

149
        $asciiVal = ord(/** @scrutinizer ignore-type */ $char);
Loading history...
150
        return $asciiVal >= Char::ZERO 
151
            && $asciiVal <= Char::NINE;
152
    }
153
154
155
    /**
156
     * Checks a character is letter or digit
157
     * 
158
     * @param char $char character to check
159
     * 
160
     * @return boolean
161
     */
162
    public static function isLetterOrDigit($char)
163
    { 
164
        return self::isDigit($char) || self::isLetter($char);
165
    }
166
}