From 4f2c33d37f1c7b7511bafee9aec49632f818f393 Mon Sep 17 00:00:00 2001 From: Neil Brayfield Date: Thu, 20 Apr 2017 08:39:35 +0100 Subject: [PATCH 1/4] Add test case for namespaces in function typehints --- test/fixtures/functions.php | 20 ++++++++++++ test/fixtures/functions.php.json | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/test/fixtures/functions.php b/test/fixtures/functions.php index 4965502..8bad7b3 100644 --- a/test/fixtures/functions.php +++ b/test/fixtures/functions.php @@ -76,6 +76,16 @@ public function getParamTypes( ) { } + ////=> param-namespace + public function paramNamespaced(\TypeHint $hint, $test) + { + } + + ////=> param-namespace-full + public function paramNamespacedFull(App\Model\TypeHint $hint, $test) + { + } + ////=> args public function dotArgs(...$args) { } @@ -106,6 +116,16 @@ public function getPHP7ReturnMultiline( ) : int { } + ////=> php7-return-namespace + public function getPHP7ReturnNamespace():\Typehint + { + } + + ////=> php7-return-namespace-full + public function getPHP7ReturnNamespaceFull():App\Model\Typehint + { + } + ////=> is public function isSomething() { diff --git a/test/fixtures/functions.php.json b/test/fixtures/functions.php.json index 928089e..caa29ef 100644 --- a/test/fixtures/functions.php.json +++ b/test/fixtures/functions.php.json @@ -188,6 +188,42 @@ ] } }, + { + "key": "param-namespace", + "name": "Param with namespaced typehint", + "result": { + "return": "void", + "params": [ + { + "name": "$hint", + "type": "\\TypeHint" + }, + + { + "name": "$test", + "type": "[type]" + } + ] + } + }, + { + "key": "param-namespace-full", + "name": "Param with fully namespaced typehint", + "result": { + "return": "void", + "params": [ + { + "name": "$hint", + "type": "App\\Model\\TypeHint" + }, + + { + "name": "$test", + "type": "[type]" + } + ] + } + }, { "key": "args", "name": "Argument with ...$args", @@ -230,6 +266,22 @@ "params": [] } }, + { + "key": "php7-return-namespace", + "name": "PHP7 return namespace type", + "result": { + "return": "\\TypeHint", + "params": [] + } + }, + { + "key": "php7-return-namespace-full", + "name": "PHP7 return namespace type", + "result": { + "return": "App\\Model\\TypeHint", + "params": [] + } + }, { "key": "php7-return-param", "name": "PHP7 return type with param", From eded5195bcb17337feee98d5c64a2cbca73e4d8c Mon Sep 17 00:00:00 2001 From: Neil Brayfield Date: Thu, 20 Apr 2017 08:44:17 +0100 Subject: [PATCH 2/4] Add class namespace test cases --- test/fixtures/classes.php | 22 ++++++++++++++++++++-- test/fixtures/classes.php.json | 12 ++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/test/fixtures/classes.php b/test/fixtures/classes.php index 961e65a..f42c50a 100644 --- a/test/fixtures/classes.php +++ b/test/fixtures/classes.php @@ -52,8 +52,8 @@ class ImplementedSubClass extends ImplementedParentClass implements ClassInterfa ////=> multiline abstract class Multiline implements ImplementedClass1, - ImplementedClass2, - ImplementedClass3 + App\Model\ImplementedClass2, + \ImplementedClass3 { } @@ -65,3 +65,21 @@ abstract class Complex extends MultilineParent implements { } + +////=> extends-namespace +class SubClass extends \ParentClass +{ + +} + +////=> implements-namespace +class ImplementedClass implements \ClassInterface +{ + +} + +////=> extends-implements-namespace +class ImplementedSubClass extends App\Model\ImplementedParentClass implements App\Model\ClassInterface +{ + +} diff --git a/test/fixtures/classes.php.json b/test/fixtures/classes.php.json index 7d36a83..fdd7850 100644 --- a/test/fixtures/classes.php.json +++ b/test/fixtures/classes.php.json @@ -38,5 +38,17 @@ { "key": "complex", "name": "Abstract extension with multline implementation" + }, + { + "key": "extends-namespace", + "name": "Extend a class with a namespace" + }, + { + "key": "implments-namespace", + "name": "Implement a class with a namespace" + }, + { + "key": "extends-implements-namespace", + "name": "Implement and implmentes classes with a namespaces" } ] From ad898db52c36d7f1a5cd6ff0eaa1ac7ac51f2eae Mon Sep 17 00:00:00 2001 From: Neil Brayfield Date: Thu, 20 Apr 2017 08:53:00 +0100 Subject: [PATCH 3/4] Fix functions with namespaced typhints --- src/block/function.ts | 4 ++-- test/fixtures/functions.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/block/function.ts b/src/block/function.ts index 6e14c03..016f080 100644 --- a/src/block/function.ts +++ b/src/block/function.ts @@ -30,7 +30,7 @@ export default class FunctionBlock extends Block let args = argString.split(','); for (let index = 0; index < args.length; index++) { let arg = args[index]; - let parts = arg.match(/^\s*([A-Za-z0-9_]+)?\s*\&?((?:[.]{3})?\$[A-Za-z0-9_]+)\s*\=?\s*(.*)\s*/m); + let parts = arg.match(/^\s*([A-Za-z0-9_\\]+)?\s*\&?((?:[.]{3})?\$[A-Za-z0-9_]+)\s*\=?\s*(.*)\s*/m); var type = '[type]'; if (parts[1] != null) { @@ -43,7 +43,7 @@ export default class FunctionBlock extends Block } } - let returnType:Array = this.signiture.match(/.*\)\s*\:\s*([a-zA-Z]+)\s*$/m); + let returnType:Array = this.signiture.match(/.*\)\s*\:\s*([a-zA-Z\\]+)\s*$/m); if (returnType != null) { doc.return = returnType[1]; diff --git a/test/fixtures/functions.php b/test/fixtures/functions.php index 8bad7b3..2b74188 100644 --- a/test/fixtures/functions.php +++ b/test/fixtures/functions.php @@ -117,12 +117,12 @@ public function getPHP7ReturnMultiline( } ////=> php7-return-namespace - public function getPHP7ReturnNamespace():\Typehint + public function getPHP7ReturnNamespace():\TypeHint { } ////=> php7-return-namespace-full - public function getPHP7ReturnNamespaceFull():App\Model\Typehint + public function getPHP7ReturnNamespaceFull():App\Model\TypeHint { } From 4fea3e42093d0f4414cae481b3aa340ae0cd0024 Mon Sep 17 00:00:00 2001 From: Neil Brayfield Date: Thu, 20 Apr 2017 09:01:23 +0100 Subject: [PATCH 4/4] Fix typo in test case --- test/fixtures/classes.php.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/classes.php.json b/test/fixtures/classes.php.json index fdd7850..0f868f5 100644 --- a/test/fixtures/classes.php.json +++ b/test/fixtures/classes.php.json @@ -44,7 +44,7 @@ "name": "Extend a class with a namespace" }, { - "key": "implments-namespace", + "key": "implements-namespace", "name": "Implement a class with a namespace" }, {