Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -1452,11 +1452,14 @@ protected String getNameAndFunctionBodyForTemplate() {
if (phpVersion != null
&& phpVersion.compareTo(PhpVersion.PHP_70) >= 0) {
Collection<TypeResolver> returnTypes = getBaseFunctionElement().getReturnTypes();
// check whether the method in question is the constructor. If it is, the return type should not be added.
boolean isConstructor = getBaseFunctionElement() instanceof MethodElement
&& ((MethodElement) getBaseFunctionElement()).getName().equals(MethodElement.CONSTRUCTOR_NAME);
// we can also write a union type in phpdoc e.g. @return int|float
// check whether the union type is actual declared return type to avoid adding the union type for phpdoc
if (returnTypes.size() == 1
if (!isConstructor && (returnTypes.size() == 1
|| getBaseFunctionElement().isReturnUnionType()
|| getBaseFunctionElement().isReturnIntersectionType()) {
|| getBaseFunctionElement().isReturnIntersectionType())) {
String returnType = getBaseFunctionElement().asString(PrintAs.ReturnTypes, typeNameResolver, phpVersion);
if (StringUtils.hasText(returnType)) {
boolean nullableType = CodeUtils.isNullableType(returnType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public final String asString(PrintAs as, BaseFunctionElement element, TypeNameRe
Collection<TypeResolver> returns1 = getReturnTypes();
// we can also write the union type in phpdoc e.g. @return int|float
// check whether the union type is the actual declared return type to avoid adding the union type for phpdoc
if (returns1.size() == 1 || isReturnUnionType() || isReturnIntersectionType()) {
if (!element.getName().equals(MethodElement.CONSTRUCTOR_NAME) && returns1.size() == 1 || isReturnUnionType() || isReturnIntersectionType()) {
String returnType = asString(PrintAs.ReturnTypes, element, typeNameResolver, phpVersion);
if (StringUtils.hasText(returnType)) {
boolean isNullableType = CodeUtils.isNullableType(returnType);
Expand Down