Skip to content

Commit

Permalink
PHP8 union properties
Browse files Browse the repository at this point in the history
  • Loading branch information
neild3r committed Aug 17, 2021
1 parent aa8ac94 commit 94b7d50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Expand Up @@ -20,6 +20,7 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/index"
],
"stopOnEntry": false,
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "npm: watch"
}
Expand Down
2 changes: 1 addition & 1 deletion src/block/property.ts
Expand Up @@ -32,7 +32,7 @@ export default class Property extends Block
head = this.getClassHead();
}

let varType = TypeUtil.instance.getFullyQualifiedType(parts[2], head);
let varType = TypeUtil.instance.getResolvedTypeHints(parts[2], head);
varType = TypeUtil.instance.getFormattedTypeByName(varType);

if (parts[1] === '?') {
Expand Down
14 changes: 12 additions & 2 deletions test/fixtures/properties.php
Expand Up @@ -47,11 +47,9 @@ abstract class Test
////=> default-float
public $defaultFloat = -124124.50;


////=> default-int
public $defaultInt = -214221;


////=> default-null
public $defaultNull = null;

Expand Down Expand Up @@ -81,4 +79,16 @@ abstract class Test

////=> typed-namespace-nullable
public ?\App\Type\Test $typedNamespaceNullable;

////=> union-type-simple
public string|array $unionTypeSimple;

////=> union-type-namespace
public string|\DateTimeInterface $unionTypeNamespace;

////=> union-type-full-namespace
public string|\App\Type\Test $unionTypeFullNamespace;

////=> union-type-nullable
public string|array|null $unionTypeNullable;
}
20 changes: 20 additions & 0 deletions test/fixtures/properties.php.json
Expand Up @@ -121,5 +121,25 @@
"config": {
"qualifyClassNames": true
}
},
{
"key": "union-type-simple",
"name": "Simple PHP8 union type",
"var": "string|array"
},
{
"key": "union-type-namespace",
"name": "PHP8 union type with one namespace",
"var": "string|\\DateTimeInterface"
},
{
"key": "union-type-full-namespace",
"name": "PHP8 union type with one namespace",
"var": "string|\\App\\Type\\Test"
},
{
"key": "union-type-nullable",
"name": "PHP8 union type that can be null",
"var": "string|array|null"
}
]

0 comments on commit 94b7d50

Please sign in to comment.