This check compares the return type specified in the @return annotation of a function
or method doc comment with the types returned by the function and raises an issue if they
mismatch.
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate
the same code in three or more different places, we strongly encourage you to
look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
27
{
28
if (empty($arguments['id'])) {
29
return;
30
}
31
32
if (array_key_exists('id', $arguments) && $arguments['id']) {
The variable $explanation does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined
for all execution paths.
Let’s take a look at an example:
functionmyFunction($a){switch($a){case'foo':$x=1;break;case'bar':$x=2;break;}// $x is potentially undefined here.echo$x;}
In the above example, the variable $x is defined if you pass “foo” or “bar”
as argument for $a. However, since the switch statement has no default
case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
functionmyFunction($a){switch($a){case'foo':$x=1;break;case'bar':$x=2;break;}if(isset($x)){// Make sure it's always set.echo$x;}}
Define a default value for the variable:
functionmyFunction($a){$x='';// Set a default which gets overridden for certain paths.switch($a){case'foo':$x=1;break;case'bar':$x=2;break;}echo$x;}
Add a value for the missing path:
functionmyFunction($a){switch($a){case'foo':$x=1;break;case'bar':$x=2;break;// We add support for the missing case.default:$x='';break;}echo$x;}
Loading history...
37
return;
38
}
39
40
if (array_key_exists('title', $arguments) && $arguments['title']) {
41
$explanation->Title = $arguments['title'];
42
}
43
44
$template = new SSViewer('ExplanationShortcode');
45
return $template->process($explanation);
46
}
47
48
/**
49
* returns a list of fields for editing the shortcode's attributes
This check compares the return type specified in the @return annotation of a function
or method doc comment with the types returned by the function and raises an issue if they
mismatch.
Loading history...
51
**/
52
public static function shortcode_attribute_fields()
53
{
54
//@todo use addnew field to add a new abbr. on the fly
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.