Passed
Pull Request — master (#66)
by Alex
03:12
created

PrimitiveTypeKind::isSpatial()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 21
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\ODataMetadata\Enums;
6
7
/**
8
 * Class EdmPrimitiveTypeKind.
9
 *
10
 *  Enumerates the kinds of Edm Primitives.
11
 *
12
 * @package AlgoWeb\ODataMetadata\MetadataV3\Enums
13
 * @method static self None() Represents a primitive type of unknown kind.
14
 * @method bool   isNone()
15
 * @method static self Binary(): self Represents a Binary type.
16
 * @method bool isBinary()
17
 * @method static self Boolean(): self Represents a Boolean type.
18
 * @method bool isBoolean()
19
 * @method static self Byte(): self Represents a Byte type.
20
 * @method bool isByte()
21
 * @method static self DateTime(): self Represents a DateTime type.
22
 * @method bool isDateTime()
23
 * @method static self DateTimeOffset(): self Represents a DateTimeOffset type.
24
 * @method bool isDateTimeOffset()
25
 * @method static self Decimal(): self Represents a Decimal type.
26
 * @method bool isDecimal()
27
 * @method static self Double(): self Represents a Double type.
28
 * @method bool isDouble()
29
 * @method static self Guid(): self Represents a Guid type.
30
 * @method bool isGuid()
31
 * @method static self Int16(): self Represents a Int16 type.
32
 * @method bool isInt16()
33
 * @method static self Int32(): self Represents a Int32 type.
34
 * @method bool isInt32()
35
 * @method static self Int64(): self Represents a Int64 type.
36
 * @method bool isInt64()
37
 * @method static self SByte(): self Represents a SByte type.
38
 * @method bool isSByte()
39
 * @method static self Single(): self Represents a Single type.
40
 * @method bool isSingle()
41
 * @method static self String(): self Represents a String type.
42
 * @method bool isString()
43
 * @method static self Stream(): Represents a Stream type.
44
 * @method bool isStream()
45
 * @method static self Time(): self Represents a Time type.
46
 * @method bool isTime()
47
 * @method static self Geography(): self Represents an arbitrary Geography type.
48
 * @method bool isGeography()
49
 * @method static self GeographyPoint(): self Represents a geography Point type.
50
 * @method bool isGeographyPoint()
51
 * @method static self GeographyLineString(): self Represents a geography LineString type.
52
 * @method bool isGeographyLineString()
53
 * @method static self GeographyPolygon(): self Represents a geography Polygon type.
54
 * @method bool isGeographyPolygon()
55
 * @method static self GeographyMultiPolygon(): self Represents a geography MultiPoint type.
56
 * @method bool isGeographyMultiPolygon()
57
 * @method static self GeographyMultiLineString(): self Represents a geography MultiLineString type.
58
 * @method bool isGeographyMultiLineString()
59
 * @method static self GeographyMultiPoint(): self Represents a geography MultiPolygon type.
60
 * @method bool isGeographyMultiPoint()
61
 * @method static self GeographyCollection(): self Represents a geography GeographyCollection type.
62
 * @method bool isGeographyCollection()
63
 * @method static self Geometry(): self Represents an arbitrary Geometry type.
64
 * @method bool isGeometry()
65
 * @method static self GeometryPoint(): self Represents a geometry Point type.
66
 * @method bool isGeometryPoint()
67
 * @method static self GeometryLineString(): self Represents a geometry LineString type.
68
 * @method bool isGeometryLineString()
69
 * @method static self GeometryPolygon(): self Represents a geometry Polygon type.
70
 * @method bool isGeometryPolygon()
71
 * @method static self GeometryMultiPoint(): self Represents a geometry MultiPoint type.
72
 * @method bool isGeometryMultiPoint()
73
 * @method static self GeometryMultiLineString(): self  Represents a geometry MultiLineString type.
74
 * @method bool isGeometryMultiLineString()
75
 * @method static self GeometryMultiPolygon(): self Represents a geometry MultiPolygon type.
76
 * @method bool isGeometryMultiPolygon()
77
 * @method static self GeometryCollection(): self  Represents a geometry GeometryCollection type.
78
 * @method bool isGeometryCollection()
79
 */
80
class PrimitiveTypeKind extends Enum
81
{
82
    /**
83
     * Represents a primitive type of unknown kind.
84
     */
85
    protected const None = '';
86
    // V1-2
87
    protected const Binary         = 'Edm.Binary';
88
    protected const Boolean        = 'Edm.Boolean';
89
    protected const Byte           = 'Edm.Byte';
90
    protected const DateTime       = 'Edm.DateTime';
91
    protected const DateTimeOffset = 'Edm.DateTimeOffset';
92
    protected const Time           = 'Edm.Time';
93
    protected const Decimal        = 'Edm.Decimal';
94
    protected const Double         = 'Edm.Double';
95
    protected const Single         = 'Edm.Single';
96
    protected const Guid           = 'Edm.Guid';
97
    protected const Int16          = 'Edm.Int16';
98
    protected const Int32          = 'Edm.Int32';
99
    protected const Int64          = 'Edm.Int64';
100
    protected const String         = 'Edm.String';
101
    protected const SByte          = 'Edm.SByte';
102
    protected const Stream         = 'Edm.Stream'; //TODO: check this value,.
103
    //V3
104
    protected const Geography                = 'Edm.Geography';
105
    protected const GeographyPoint           = 'Edm.Point';
106
    protected const GeographyLineString      = 'Edm.LineString';
107
    protected const GeographyPolygon         = 'Edm.Polygon';
108
    protected const GeographyMultiPolygon    = 'Edm.MultiPoint';
109
    protected const GeographyMultiLineString = 'Edm.MultiLineString';
110
    protected const GeographyMultiPoint      = 'Edm.MultiPolygon';
111
    protected const GeographyCollection      = 'Edm.GeographyCollection';
112
    protected const Geometry                 = 'Edm.Geometry';
113
    protected const GeometryPoint            = 'Edm.GeometricPoint';
114
    protected const GeometryLineString       = 'Edm.GeometricLineString';
115
    protected const GeometryPolygon          = 'Edm.Edm.GeometricPolygon';
116
    protected const GeometryMultiPoint       = 'Edm.GeometricMultiPoint';
117
    protected const GeometryMultiLineString  = 'Edm.GeometricMultiLineString';
118
    protected const GeometryMultiPolygon     = 'Edm.GeometricMultiPolygon';
119
    protected const GeometryCollection       = 'Edm.GeometryCollection';
120
121
    /**
122
     * Returns true if this type kind represents a spatial type.
123
     *
124
     * @return bool this kind refers to a spatial type
125
     */
126
    public function isSpatial(): bool
127
    {
128
        $spatialTypes = [
129
            self::Geography,
130
            self::GeographyPoint,
131
            self::GeographyLineString,
132
            self::GeographyPolygon,
133
            self::GeographyCollection,
134
            self::GeographyMultiPoint,
135
            self::GeographyMultiLineString,
136
            self::GeographyMultiPolygon,
137
            self::Geometry,
138
            self::GeometryPoint,
139
            self::GeometryLineString,
140
            self::GeometryPolygon,
141
            self::GeometryCollection,
142
            self::GeometryMultiPolygon,
143
            self::GeometryMultiLineString,
144
            self::GeometryMultiPoint
145
        ];
146
        return in_array($this->getValue(), $spatialTypes);
147
    }
148
149
    /**
150
     * Returns true if this type kind represents a temporal type.
151
     *
152
     * @return bool this kind refers to a temporal type
153
     */
154
    public function isTemporal(): bool
155
    {
156
        $temporalTypes = [
157
            self::Time,
158
            self::DateTime,
159
            self::DateTimeOffset,
160
        ];
161
        return in_array($this->getValue(), $temporalTypes);
162
    }
163
164
    /**
165
     * Returns true if this primitive type kind represents an integer type.
166
     *
167
     * @return bool this kind refers to an integer type
168
     */
169
    public function isIntegral(): bool
170
    {
171
        $integralTypes = [
172
            self::Int64,
173
            self::Int32,
174
            self::Int16,
175
            self::Byte,
176
            self::SByte,
177
        ];
178
        return in_array($this->getValue(), $integralTypes);
179
    }
180
181
182
    /**
183
     * Returns true if this reference refers to a signed integral type.
184
     *
185
     * @return bool this reference refers to a signed integral type
186
     */
187
    public function isSignedIntegral(): bool
188
    {
189
        $value = $this->getValue();
190
191
        $signedIntegralTypes = [
192
            self::Int64,
193
            self::Int32,
194
            self::Int16,
195
            self::SByte,
196
        ];
197
198
        return in_array($value, $signedIntegralTypes);
199
    }
200
}
201