Completed
Push — master ( 24a065...25878f )
by CodexShaper
06:29
created

Type::relationship()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace CodexShaper\DBM\Database\Drivers\MongoDB;
4
5
use MongoDB\BSON\Binary;
6
use MongoDB\BSON\Decimal128 as Decimal;
7
use MongoDB\BSON\Javascript;
8
use MongoDB\BSON\MaxKey;
9
use MongoDB\BSON\MinKey;
10
use MongoDB\BSON\ObjectId;
11
use MongoDB\BSON\Regex;
12
use MongoDB\BSON\Timestamp;
13
use MongoDB\BSON\UTCDateTime;
14
15
class Type
16
{
17
    protected static $types = [
18
        'binary',
19
        'decimal',
20
        'javascript',
21
        'maxKey',
22
        'minKey',
23
        'objectId',
24
        'regex',
25
        'timestamp',
26
        'dateTime',
27
        'string',
28
        'arrayType',
29
        'object',
30
        'boolean',
31
        'double',
32
        'null',
33
        'integer',
34
        'longInteger',
35
        'relationship',
36
    ];
37
38
    /**
39
     * Get binary
40
     *
41
     * @return  \MongoDB\BSON\Binary
42
     */
43
    public static function binary(string $value, int $type = Binary::TYPE_GENERIC)
44
    {
45
        return new Binary($value, $type);
46
    }
47
    /**
48
     * Get decimal
49
     *
50
     * @return  \MongoDB\BSON\Decimal128
51
     */
52
    public static function decimal(string $value)
53
    {
54
        return new Decimal($value);
55
    }
56
    /**
57
     * Get javascript
58
     *
59
     * @param   string  $code
60
     * @param   array   $scope
61
     *
62
     * @return  \MongoDB\BSON\Javascript
63
     */
64
    public static function javascript(string $code, $scope = [])
65
    {
66
        if (!is_array($scope) || !is_array()) {
0 ignored issues
show
introduced by
The condition is_array($scope) is always true.
Loading history...
Bug introduced by
The call to is_array() has too few arguments starting with var. ( Ignorable by Annotation )

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

66
        if (!is_array($scope) || !/** @scrutinizer ignore-call */ is_array()) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
67
            throw new \Exception($scope . " should be array or object");
68
69
        }
70
71
        return new Javascript($code, $scope);
72
    }
73
    /**
74
     * Get max key
75
     *
76
     * @return  \MongoDB\BSON\MaxKey
77
     */
78
    public static function maxKey()
79
    {
80
        return new MaxKey();
81
    }
82
    /**
83
     * Get min key
84
     *
85
     * @return  \MongoDB\BSON\MinKey
86
     */
87
    public static function minKey()
88
    {
89
        return new MinKey();
90
    }
91
    /**
92
     * Get ObjectId
93
     *
94
     * @return  \MongoDB\BSON\ObjectId
95
     */
96
    public static function objectId(string $value)
97
    {
98
        return new ObjectId($value);
99
    }
100
    /**
101
     * Get regular expression
102
     *
103
     * @return  \MongoDB\BSON\Regex
104
     */
105
    public static function regex(string $pattern, string $flags)
0 ignored issues
show
Unused Code introduced by
The parameter $flags is not used and could be removed. ( Ignorable by Annotation )

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

105
    public static function regex(string $pattern, /** @scrutinizer ignore-unused */ string $flags)

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

Loading history...
Unused Code introduced by
The parameter $pattern is not used and could be removed. ( Ignorable by Annotation )

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

105
    public static function regex(/** @scrutinizer ignore-unused */ string $pattern, string $flags)

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

Loading history...
106
    {
107
        return new Regex($value);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value seems to be never defined.
Loading history...
108
    }
109
    /**
110
     * Get timestamp
111
     *
112
     * @return  \MongoDB\BSON\Timestamp
113
     */
114
    public static function timestamp(int $increment, int $timestamp)
115
    {
116
        return new Timestamp($increment, $timestamp);
117
    }
118
    /**
119
     * Get datetime
120
     *
121
     * @param int|nul $milliseconds
0 ignored issues
show
Bug introduced by
The type CodexShaper\DBM\Database\Drivers\MongoDB\nul was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
122
     *
123
     * @return  \MongoDB\BSON\UTCDateTime
124
     */
125
    public static function dateTime($milliseconds = null)
126
    {
127
        if (!is_int($milliseconds) || !is_float($milliseconds) || !is_string($milliseconds) || !$milliseconds instanceof \DateTimeInterface) {
0 ignored issues
show
introduced by
The condition is_float($milliseconds) is always false.
Loading history...
128
            throw new \Exception($milliseconds . " integer or float or string or instance of DateTimeInterface");
129
130
        }
131
        return new UTCDateTime($milliseconds);
132
    }
133
    /**
134
     * Get string
135
     *
136
     * @param string $value
137
     *
138
     * @return  string
139
     */
140
    public static function string($value)
141
    {
142
        return (string) $value;
143
    }
144
    /**
145
     * Get array
146
     *
147
     * @param array $value
148
     *
149
     * @return  array
150
     */
151
    public static function arrayType($value)
152
    {
153
        return (array) $value;
154
    }
155
    /**
156
     * Get object
157
     *
158
     * @param object $value
159
     *
160
     * @return  object
161
     */
162
    public static function object($value)
163
    {
164
        return (object) $value;
165
    }
166
    /**
167
     * Get boolean
168
     *
169
     * @param bool $value
170
     *
171
     * @return  bool
172
     */
173
    public static function boolean($value)
174
    {
175
        return (boolean) $value;
176
    }
177
    /**
178
     * Get double
179
     *
180
     * @param double $value
181
     *
182
     * @return  double
183
     */
184
    public static function double($value)
185
    {
186
        return (double) $value;
187
    }
188
    /**
189
     * Get null
190
     *
191
     * @return  null
192
     */
193
    public static function null()
194
    {
195
        return null;
196
    }
197
    /**
198
     * Get integer
199
     *
200
     * @param int $value
201
     *
202
     * @return  int
203
     */
204
    public static function integer($value)
205
    {
206
        return (int) $value;
207
    }
208
    /**
209
     * Get long integer
210
     *
211
     * @param int $value
212
     *
213
     * @return  int
214
     */
215
    public static function longInteger($value)
216
    {
217
        return (int) $value;
218
    }
219
    /**
220
     * Get types
221
     *
222
     * @return  array
223
     */
224
    public static function getTypes()
225
    {
226
        return (array) self::$types;
227
    }
228
}
229