-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPHP85.class.php
More file actions
executable file
·57 lines (53 loc) · 1.57 KB
/
PHP85.class.php
File metadata and controls
executable file
·57 lines (53 loc) · 1.57 KB
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
<?php namespace lang\ast\emit;
use lang\ast\types\{
IsArray,
IsFunction,
IsGeneric,
IsIntersection,
IsLiteral,
IsMap,
IsNullable,
IsUnion,
IsValue
};
/**
* PHP 8.5 syntax
*
* @test lang.ast.unittest.emit.PHP85Test
* @see https://wiki.php.net/rfc#php_85
*/
class PHP85 extends PHP {
use RewriteBlockLambdaExpressions, RewriteCallables;
public $targetVersion= 80500;
/** Sets up type => literal mappings */
public function __construct() {
$this->literals= [
IsArray::class => function($t) { return 'array'; },
IsMap::class => function($t) { return 'array'; },
IsFunction::class => function($t) { return 'callable'; },
IsValue::class => function($t) { return $t->literal(); },
IsNullable::class => function($t) {
if (null === ($l= $this->literal($t->element))) return null;
return $t->element instanceof IsUnion ? $l.'|null' : '?'.$l;
},
IsIntersection::class => function($t) {
$i= '';
foreach ($t->components as $component) {
if (null === ($l= $this->literal($component))) return null;
$i.= '&'.$l;
}
return substr($i, 1);
},
IsUnion::class => function($t) {
$u= '';
foreach ($t->components as $component) {
if (null === ($l= $this->literal($component))) return null;
$u.= '|'.$l;
}
return substr($u, 1);
},
IsLiteral::class => function($t) { return $t->literal(); },
IsGeneric::class => function($t) { return null; }
];
}
}