mago-codex 1.47.0

PHP type system representation, comparison logic, and codebase metadata for static analysis.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
use mago_database::file::FileType;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MetadataFlags(u64);

impl MetadataFlags {
    #[inline]
    #[must_use]
    pub const fn bits(self) -> u64 {
        self.0
    }

    pub const ABSTRACT: MetadataFlags = MetadataFlags(1 << 0);
    pub const FINAL: MetadataFlags = MetadataFlags(1 << 1);
    pub const READONLY: MetadataFlags = MetadataFlags(1 << 3);
    pub const DEPRECATED: MetadataFlags = MetadataFlags(1 << 4);
    pub const ENUM_INTERFACE: MetadataFlags = MetadataFlags(1 << 5);
    pub const POPULATED: MetadataFlags = MetadataFlags(1 << 6);
    pub const INTERNAL: MetadataFlags = MetadataFlags(1 << 7);
    pub const CONSISTENT_CONSTRUCTOR: MetadataFlags = MetadataFlags(1 << 11);
    pub const CONSISTENT_TEMPLATES: MetadataFlags = MetadataFlags(1 << 12);
    pub const UNCHECKED: MetadataFlags = MetadataFlags(1 << 13);
    pub const USER_DEFINED: MetadataFlags = MetadataFlags(1 << 14);
    pub const BUILTIN: MetadataFlags = MetadataFlags(1 << 15);
    pub const HAS_YIELD: MetadataFlags = MetadataFlags(1 << 16);
    pub const MUST_USE: MetadataFlags = MetadataFlags(1 << 17);
    pub const HAS_THROW: MetadataFlags = MetadataFlags(1 << 18);
    pub const PURE: MetadataFlags = MetadataFlags(1 << 19);
    pub const IGNORE_NULLABLE_RETURN: MetadataFlags = MetadataFlags(1 << 20);
    pub const IGNORE_FALSABLE_RETURN: MetadataFlags = MetadataFlags(1 << 21);
    pub const INHERITS_DOCS: MetadataFlags = MetadataFlags(1 << 22);
    pub const NO_NAMED_ARGUMENTS: MetadataFlags = MetadataFlags(1 << 23);
    pub const BACKED_ENUM_CASE: MetadataFlags = MetadataFlags(1 << 24);
    pub const UNIT_ENUM_CASE: MetadataFlags = MetadataFlags(1 << 25);
    pub const BY_REFERENCE: MetadataFlags = MetadataFlags(1 << 26);
    pub const VARIADIC: MetadataFlags = MetadataFlags(1 << 27);
    pub const PROMOTED_PROPERTY: MetadataFlags = MetadataFlags(1 << 28);
    pub const HAS_DEFAULT: MetadataFlags = MetadataFlags(1 << 29);
    pub const VIRTUAL_PROPERTY: MetadataFlags = MetadataFlags(1 << 30);
    pub const ASYMMETRIC_PROPERTY: MetadataFlags = MetadataFlags(1 << 31);
    pub const STATIC: MetadataFlags = MetadataFlags(1 << 32);
    pub const WRITEONLY: MetadataFlags = MetadataFlags(1 << 33);
    // Bit 34 was MAGIC_PROPERTY; magic properties are now identified by their entry in
    // `ClassLikeMetadata::magic_properties` instead of a flag.
    pub const MAGIC_METHOD: MetadataFlags = MetadataFlags(1 << 35);
    pub const API: MetadataFlags = MetadataFlags(1 << 36);
    pub const MUTATION_FREE: MetadataFlags = MetadataFlags(1 << 37);
    pub const EXTERNAL_MUTATION_FREE: MetadataFlags = MetadataFlags(1 << 38);
    pub const SUSPENDS_FIBER: MetadataFlags = MetadataFlags(1 << 39);
    pub const EXPERIMENTAL: MetadataFlags = MetadataFlags(1 << 40);
    pub const POLYFILL: MetadataFlags = MetadataFlags(1 << 41);
    pub const PATCH: MetadataFlags = MetadataFlags(1 << 42);
    pub const EXTERNAL: MetadataFlags = MetadataFlags(1 << 43);
}

impl MetadataFlags {
    #[inline]
    #[must_use]
    pub const fn from_bits(bits: u64) -> Self {
        Self(bits)
    }

    #[inline]
    #[must_use]
    pub const fn empty() -> Self {
        MetadataFlags(0)
    }

    #[inline]
    pub const fn insert(&mut self, other: MetadataFlags) {
        self.0 |= other.0;
    }

    #[inline]
    pub const fn set(&mut self, other: MetadataFlags, value: bool) {
        if value {
            self.insert(other);
        } else {
            self.0 &= !other.0;
        }
    }

    #[inline]
    #[must_use]
    pub const fn contains(self, other: MetadataFlags) -> bool {
        (self.0 & other.0) == other.0
    }

    #[inline]
    pub const fn remove(&mut self, other: MetadataFlags) {
        self.0 &= !other.0;
    }

    #[inline]
    #[must_use]
    pub const fn intersects(self, other: MetadataFlags) -> bool {
        (self.0 & other.0) != 0
    }

    #[inline]
    #[must_use]
    pub const fn union(&self, other: MetadataFlags) -> MetadataFlags {
        MetadataFlags(self.0 | other.0)
    }

    #[inline]
    #[must_use]
    pub const fn intersection(&self, other: MetadataFlags) -> MetadataFlags {
        MetadataFlags(self.0 & other.0)
    }
}

impl MetadataFlags {
    #[inline]
    #[must_use]
    pub const fn is_deprecated(self) -> bool {
        self.contains(Self::DEPRECATED)
    }

    #[inline]
    #[must_use]
    pub const fn is_abstract(self) -> bool {
        self.contains(Self::ABSTRACT)
    }

    #[inline]
    #[must_use]
    pub const fn is_final(self) -> bool {
        self.contains(Self::FINAL)
    }

    #[inline]
    #[must_use]
    pub const fn has_yield(self) -> bool {
        self.contains(Self::HAS_YIELD)
    }

    #[inline]
    #[must_use]
    pub const fn must_use(self) -> bool {
        self.contains(Self::MUST_USE)
    }

    #[inline]
    #[must_use]
    pub const fn is_pure(self) -> bool {
        self.contains(Self::PURE)
    }

    #[inline]
    #[must_use]
    pub const fn has_consistent_constructor(self) -> bool {
        self.contains(Self::CONSISTENT_CONSTRUCTOR)
    }

    #[inline]
    #[must_use]
    pub const fn has_consistent_templates(self) -> bool {
        self.contains(Self::CONSISTENT_TEMPLATES)
    }

    #[inline]
    #[must_use]
    pub const fn is_user_defined(self) -> bool {
        self.contains(Self::USER_DEFINED)
    }

    #[inline]
    #[must_use]
    pub const fn is_built_in(self) -> bool {
        self.contains(Self::BUILTIN)
    }

    #[inline]
    #[must_use]
    pub const fn is_internal(self) -> bool {
        self.contains(Self::INTERNAL)
    }

    #[inline]
    #[must_use]
    pub const fn is_populated(self) -> bool {
        self.contains(Self::POPULATED)
    }

    #[inline]
    #[must_use]
    pub const fn is_readonly(self) -> bool {
        self.contains(Self::READONLY)
    }

    #[inline]
    #[must_use]
    pub const fn is_writeonly(self) -> bool {
        self.contains(Self::WRITEONLY)
    }

    #[inline]
    #[must_use]
    pub const fn is_enum_interface(self) -> bool {
        self.contains(Self::ENUM_INTERFACE)
    }

    #[inline]
    #[must_use]
    pub const fn is_unchecked(self) -> bool {
        self.contains(Self::UNCHECKED)
    }

    #[inline]
    #[must_use]
    pub const fn ignore_nullable_return(self) -> bool {
        self.contains(Self::IGNORE_NULLABLE_RETURN)
    }

    #[inline]
    #[must_use]
    pub const fn ignore_falsable_return(self) -> bool {
        self.contains(Self::IGNORE_FALSABLE_RETURN)
    }

    #[inline]
    #[must_use]
    pub const fn inherits_docs(self) -> bool {
        self.contains(Self::INHERITS_DOCS)
    }

    #[inline]
    #[must_use]
    pub const fn forbids_named_arguments(self) -> bool {
        self.contains(Self::NO_NAMED_ARGUMENTS)
    }

    #[inline]
    #[must_use]
    pub const fn has_throw(self) -> bool {
        self.contains(Self::HAS_THROW)
    }

    #[inline]
    #[must_use]
    pub const fn is_backed_enum_case(self) -> bool {
        self.contains(Self::BACKED_ENUM_CASE)
    }

    #[inline]
    #[must_use]
    pub const fn is_unit_enum_case(self) -> bool {
        self.contains(Self::UNIT_ENUM_CASE)
    }

    #[inline]
    #[must_use]
    pub const fn is_by_reference(self) -> bool {
        self.contains(Self::BY_REFERENCE)
    }

    #[inline]
    #[must_use]
    pub const fn is_variadic(self) -> bool {
        self.contains(Self::VARIADIC)
    }

    #[inline]
    #[must_use]
    pub const fn is_promoted_property(self) -> bool {
        self.contains(Self::PROMOTED_PROPERTY)
    }

    #[inline]
    #[must_use]
    pub const fn has_default(self) -> bool {
        self.contains(Self::HAS_DEFAULT)
    }

    #[inline]
    #[must_use]
    pub const fn is_virtual_property(self) -> bool {
        self.contains(Self::VIRTUAL_PROPERTY)
    }

    #[inline]
    #[must_use]
    pub const fn is_magic_method(self) -> bool {
        self.contains(Self::MAGIC_METHOD)
    }

    #[inline]
    #[must_use]
    pub const fn is_asymmetric_property(self) -> bool {
        self.contains(Self::ASYMMETRIC_PROPERTY)
    }

    #[inline]
    #[must_use]
    pub const fn is_static(self) -> bool {
        self.contains(Self::STATIC)
    }

    #[inline]
    #[must_use]
    pub const fn is_public_api(self) -> bool {
        self.contains(Self::API)
    }

    #[inline]
    #[must_use]
    pub const fn is_experimental(self) -> bool {
        self.contains(Self::EXPERIMENTAL)
    }

    #[inline]
    #[must_use]
    pub const fn is_mutation_free(self) -> bool {
        self.contains(Self::MUTATION_FREE)
    }

    #[inline]
    #[must_use]
    pub const fn is_external_mutation_free(self) -> bool {
        self.contains(Self::EXTERNAL_MUTATION_FREE)
    }

    #[inline]
    #[must_use]
    pub const fn suspends_fiber(self) -> bool {
        self.contains(Self::SUSPENDS_FIBER)
    }

    #[inline]
    #[must_use]
    pub const fn is_polyfill(self) -> bool {
        self.contains(Self::POLYFILL)
    }

    #[inline]
    #[must_use]
    pub const fn is_patch(self) -> bool {
        self.contains(Self::PATCH)
    }

    #[inline]
    #[must_use]
    pub const fn is_external(self) -> bool {
        self.contains(Self::EXTERNAL)
    }

    #[inline]
    #[must_use]
    pub const fn origin_flags(file_type: FileType) -> Self {
        match file_type {
            FileType::Host => Self::USER_DEFINED,
            FileType::Builtin => Self::BUILTIN,
            FileType::Patch => Self::PATCH,
            FileType::External => Self::EXTERNAL,
            FileType::Vendored => Self::empty(),
        }
    }
}

impl std::ops::BitOr for MetadataFlags {
    type Output = Self;

    #[inline]
    fn bitor(self, rhs: Self) -> Self::Output {
        MetadataFlags(self.0 | rhs.0)
    }
}

impl std::ops::BitAnd for MetadataFlags {
    type Output = Self;

    #[inline]
    fn bitand(self, rhs: Self) -> Self::Output {
        MetadataFlags(self.0 & rhs.0)
    }
}

impl std::ops::BitXor for MetadataFlags {
    type Output = Self;

    #[inline]
    fn bitxor(self, rhs: Self) -> Self::Output {
        MetadataFlags(self.0 ^ rhs.0)
    }
}

impl std::ops::Not for MetadataFlags {
    type Output = Self;

    #[inline]
    fn not(self) -> Self::Output {
        MetadataFlags(!self.0)
    }
}

impl std::ops::BitOrAssign for MetadataFlags {
    #[inline]
    fn bitor_assign(&mut self, rhs: Self) {
        self.0 |= rhs.0;
    }
}

impl std::ops::BitAndAssign for MetadataFlags {
    #[inline]
    fn bitand_assign(&mut self, rhs: Self) {
        self.0 &= rhs.0;
    }
}

impl std::ops::BitXorAssign for MetadataFlags {
    #[inline]
    fn bitxor_assign(&mut self, rhs: Self) {
        self.0 ^= rhs.0;
    }
}