Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace issues #33

Merged
merged 4 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/block/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -43,7 +43,7 @@ export default class FunctionBlock extends Block
}
}

let returnType:Array<string> = this.signiture.match(/.*\)\s*\:\s*([a-zA-Z]+)\s*$/m);
let returnType:Array<string> = this.signiture.match(/.*\)\s*\:\s*([a-zA-Z\\]+)\s*$/m);

if (returnType != null) {
doc.return = returnType[1];
Expand Down
22 changes: 20 additions & 2 deletions test/fixtures/classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ImplementedSubClass extends ImplementedParentClass implements ClassInterfa
////=> multiline
abstract class Multiline implements
ImplementedClass1,
ImplementedClass2,
ImplementedClass3
App\Model\ImplementedClass2,
\ImplementedClass3
{

}
Expand All @@ -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
{

}
12 changes: 12 additions & 0 deletions test/fixtures/classes.php.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,17 @@
{
"key": "complex",
"name": "Abstract extension with multline implementation"
},
{
"key": "extends-namespace",
"name": "Extend a class with a namespace"
},
{
"key": "implements-namespace",
"name": "Implement a class with a namespace"
},
{
"key": "extends-implements-namespace",
"name": "Implement and implmentes classes with a namespaces"
}
]
20 changes: 20 additions & 0 deletions test/fixtures/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down Expand Up @@ -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()
{
Expand Down
52 changes: 52 additions & 0 deletions test/fixtures/functions.php.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down