Skip to content

Commit

Permalink
Merge 56277f2 into 709084e
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyiw2013 committed May 16, 2021
2 parents 709084e + 56277f2 commit 262bbee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/block/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export default class FunctionBlock extends Block

if (parts[2] != null && parts[1] === '?') {
type = TypeUtil.instance.getFormattedTypeByName(parts[2])+'|null';
} else if (parts[2] != null && parts[1] === undefined && parts[4] === "null") {// int $var = null
type = TypeUtil.instance.getFormattedTypeByName(parts[2])+'|null';
} else if (parts[2] != null) {
type = TypeUtil.instance.getFormattedTypeByName(parts[2]);
} else if (parts[4] != null && parts[4] != "") {
Expand All @@ -59,7 +61,7 @@ export default class FunctionBlock extends Block
}
}

let returnType:Array<string> = this.signature.match(/.*\)\s*\:\s*(\?)?\s*([a-zA-Z_0-9\\]+)\s*$/m);
let returnType:Array<string> = this.signature.match(/.*\)\s*\:\s*(\?)?\s*([a-zA-Z_0-9\|\\]+)\s*$/m);

if (returnType != null) {
if (Config.instance.get('qualifyClassNames')) {
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function paramNamespacedFull(App\Model\TypeHint $hint, $test)
{
}

////=> param-default-null
public function paramDefaultNull(int $arg = null)
{
}

////=> args
public function dotArgs(...$args) {
}
Expand Down Expand Up @@ -156,6 +161,11 @@ public function getPHP7ReturnNamespaceFull():App\Model\TypeHint
{
}

////=> php8-union-types
public function getPHP8UnionTypes():int|bool|\TypeHint|App\Model\TypeHint
{
}

////=> function-reference
public function &someFunction()
{
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/functions.php.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@
]
}
},
{
"key": "param-default-null",
"name": "Param with default null",
"result": {
"return": "void",
"params": [
{
"name": "$arg",
"type": "integer|null"
}
]
}
},
{
"key": "args",
"name": "Argument with ...$args",
Expand Down Expand Up @@ -344,6 +357,14 @@
"params": []
}
},
{
"key": "php8-union-types",
"name": "PHP8 union types",
"result": {
"return": "int|bool|\\TypeHint|App\\Model\\TypeHint",
"params": []
}
},
{
"key": "function-reference",
"name": "Function with reference ampersand",
Expand Down

0 comments on commit 262bbee

Please sign in to comment.