Skip to content

Commit

Permalink
Merge branch 'php81' into php81-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyiw2013 committed Feb 11, 2022
2 parents 7ae1063 + 5cb3915 commit 40f1b46
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ All notable changes to the "php-docblocker" extension will be documented in this
- Supported fully qualifies class namespace use with bracket `use some\namespace\{ ClassA, ClassB, ... }`
- Supported fully qualifies class namespace use with comma `use some\namespace\ClassA, some\namespace\ClassB, ...`
- Fix issue with coverage reports not firing
- Supported PHP 8.1 Readonly Properties
- Supported PHP 8.1 Intersection Types


## [2.6.1] - 2021-10-12
- Fix double start delimeter when vscode setting `editor.autoClosingBrackets` is set to `never`
Expand Down
4 changes: 2 additions & 2 deletions src/block/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default class FunctionBlock extends Block

for (let index = 0; index < args.length; index++) {
let arg:string = args[index];
let parts:string[] = arg.match(/^\s*(?:(?:public|protected|private)\s+)?(\?)?\s*([A-Za-z0-9|_\\]+)?\s*\&?((?:[.]{3})?\$[A-Za-z0-9_]+)\s*\=?\s*(.*)\s*/im);
var type:string = TypeUtil.instance.getDefaultType();
let parts:string[] = arg.match(/^\s*(?:(?:public|protected|private)\s+)?(?:readonly\s+)?(\?)?\s*([A-Za-z0-9_\\][A-Za-z0-9_\\|&]+)?\s*\&?((?:[.]{3})?\$[A-Za-z0-9_]+)\s*\=?\s*(.*)\s*/im);
var type:string = '[type]';

if (parts[2] != null) {
type = TypeUtil.instance.getResolvedTypeHints(parts[2], head);
Expand Down
2 changes: 1 addition & 1 deletion src/block/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Property extends Block
/**
* @inheritdoc
*/
protected pattern:RegExp = /^\s*(static)?\s*(protected|private|public)\s+(static)?\s*(\??\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9|_\x7f-\xff\\]+)?\s*(\$[A-Za-z0-9_]+)\s*\=?\s*([^;]*)/m;
protected pattern:RegExp = /^\s*(static)?\s*(protected|private|public)\s+(static\s*)?(?:readonly\s*)?(\??\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9|_\x7f-\xff\\]+)?\s*(\$[A-Za-z0-9_]+)\s*\=?\s*([^;]*)/m;

/**
* @inheritdoc
Expand Down
12 changes: 8 additions & 4 deletions src/util/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ export default class TypeUtil {
*/
public getResolvedTypeHints(types:string, head:string = null): string
{
let union:string[] = types.split("|");

for (let index = 0; index < union.length; index++) {
let union:string[] = types.split(/([|&])/);
for (let index = 0; index < union.length; index += 2) {
if (union[index] === '') {
delete union[index];
delete union[index+1];
continue;
}
union[index] = this.getFullyQualifiedType(union[index], head);
union[index] = this.getFormattedTypeByName(union[index]);
}

return union.join("|");
return union.join('');
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ public function trailingCommaMulit(
) {
}

////=> php81-intersection-types
function intersection_types(Iterator&\Countable $var)
{
}

////=> php81-union-intersection-types-fault-tolerant
function union_intersection_types_fault_tolerant(Iterator&\Countable|Aaa||&|&Bbb &$var)
{
}

////=> function-reference
public function &someFunction()
{
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures/functions.php.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,32 @@
]
}
},
{
"key": "php81-intersection-types",
"name": "PHP8.1 intersection types",
"result": {
"return": "void",
"params": [
{
"name": "$var",
"type": "Iterator&\\Countable"
}
]
}
},
{
"key": "php81-union-intersection-types-fault-tolerant",
"name": "PHP8.1 unionin types AND tersection types with fault-tolerant",
"result": {
"return": "void",
"params": [
{
"name": "$var",
"type": "Iterator&\\Countable|Aaa|Bbb"
}
]
}
},
{
"key": "function-reference",
"name": "Function with reference ampersand",
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ abstract class Test

////=> union-type-nullable
public string|array|null $unionTypeNullable;

////=> readonly
public readonly string $readonly;
}
5 changes: 5 additions & 0 deletions test/fixtures/properties.php.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,10 @@
"key": "union-type-nullable",
"name": "PHP8 union type that can be null",
"var": "string|array|null"
},
{
"key": "readonly",
"name": "PHP8.1 readonly",
"var": "string"
}
]

0 comments on commit 40f1b46

Please sign in to comment.