Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coder-3216641
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
coder-3216641
Commits
216f9200
Commit
216f9200
authored
Jul 4, 2014
by
Klaus Purer
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2288837
: Fixed @return sniff to not throw errors when description is missing for $this.
parent
cedc01a9
Branches
Branches containing commit
Tags
8.2.0-alpha2
8.x-2.0-alpha2
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
+10
-9
10 additions, 9 deletions
...sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
coder_sniffer/Test/good/good.php
+9
-0
9 additions, 0 deletions
coder_sniffer/Test/good/good.php
with
19 additions
and
9 deletions
coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
+
10
−
9
View file @
216f9200
...
...
@@ -166,15 +166,16 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S
}
}
$type
=
null
;
if
(
$isSpecialMethod
===
false
&&
$methodName
!==
$className
)
{
if
(
$return
!==
null
)
{
$
content
=
$tokens
[(
$return
+
2
)][
'content'
];
if
(
empty
(
$
content
)
===
true
||
$tokens
[(
$return
+
2
)][
'code'
]
!==
T_DOC_COMMENT_STRING
)
{
$
type
=
$tokens
[(
$return
+
2
)][
'content'
];
if
(
empty
(
$
type
)
===
true
||
$tokens
[(
$return
+
2
)][
'code'
]
!==
T_DOC_COMMENT_STRING
)
{
$error
=
'Return type missing for @return tag in function comment'
;
$phpcsFile
->
addError
(
$error
,
$return
,
'MissingReturnType'
);
}
else
{
// Check return type (can be multiple, separated by '|').
$typeNames
=
explode
(
'|'
,
$
content
);
$typeNames
=
explode
(
'|'
,
$
type
);
$suggestedNames
=
array
();
foreach
(
$typeNames
as
$i
=>
$typeName
)
{
$suggestedName
=
$this
->
suggestType
(
$typeName
);
...
...
@@ -184,25 +185,25 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S
}
$suggestedType
=
implode
(
'|'
,
$suggestedNames
);
if
(
$
content
!==
$suggestedType
)
{
if
(
$
type
!==
$suggestedType
)
{
$error
=
'Function return type "%s" is invalid'
;
$error
=
'Expected "%s" but found "%s" for function return type'
;
$data
=
array
(
$suggestedType
,
$
content
,
$
type
,
);
$phpcsFile
->
addError
(
$error
,
$return
,
'InvalidReturn'
,
$data
);
}
if
(
$
content
[
0
]
===
'$'
&&
$
content
!==
'$this'
)
{
if
(
$
type
[
0
]
===
'$'
&&
$
type
!==
'$this'
)
{
$error
=
'@return data type must not contain "$"'
;
$phpcsFile
->
addError
(
$error
,
$return
,
'$InReturnType'
);
}
if
(
$
content
===
'void'
)
{
if
(
$
type
===
'void'
)
{
$error
=
'If there is no return value for a function, there must not be a @return tag.'
;
$phpcsFile
->
addError
(
$error
,
$return
,
'VoidReturn'
);
}
else
if
(
$
content
!==
'mixed'
)
{
}
else
if
(
$
type
!==
'mixed'
)
{
// If return type is not void, there needs to be a return statement
// somewhere in the function that returns something.
if
(
isset
(
$tokens
[
$stackPtr
][
'scope_closer'
])
===
true
)
{
...
...
@@ -242,7 +243,7 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S
}
}
}
if
(
$comment
==
''
)
{
if
(
$comment
==
=
''
&&
$type
!==
'$this'
)
{
$error
=
'Return comment must be on the next line'
;
$phpcsFile
->
addError
(
$error
,
$return
,
'MissingReturnComment'
);
}
//end if
...
...
This diff is collapsed.
Click to expand it.
coder_sniffer/Test/good/good.php
+
9
−
0
View file @
216f9200
...
...
@@ -635,6 +635,15 @@ class Foo implements FooInterface {
public
function
__toString
()
{
return
'foo'
;
}
/**
* Omitting the comment when returning $this is allowed.
*
* @return $this
*/
public
function
test4
()
{
return
$this
;
}
}
t
(
'Some long mulit-line
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment