The trait Idable provides a method equalsId that in turn relies on the
method getId(). If this method does not exist on a class mixing in this
trait, the method will fail.
Adding the getId() as an abstract method to the trait will make sure it
is available.
The call to Update::data() has too many arguments starting with array('vars' => '', 'bod... 'compiled_body' => '').
This check compares calls to functions or methods with their respective definitions.
If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the
check may pick up the wrong definition and report false positives. One codebase
where this has been known to happen is Wordpress.
In this case you can add the @ignorePhpDoc
annotation to the duplicate definition and it will be ignored.
Loading history...
28
1
'vars' => '',
29
'body' => '',
30
'compiled_subject' => '',
31
'compiled_body' => '',
32
]);
33
34
1
return $query->execute();
35
}
36
37
/**
38
* @return string
39
*/
40
2
public static function getSentDateField(): string
41
{
42
2
return self::$sentDateField;
43
}
44
45
/**
46
* @param string $sentDateField
47
*/
48
public static function setSentDateField(string $sentDateField)
$types was never initialized. Although not strictly required by PHP, it is generally a good practice to add $types = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array
definition as it guarantees a stable state of the code.
Let’s take a look at an example:
foreach($collectionas$item){$myArray['foo']=$item->getFoo();if($item->hasBar()){$myArray['bar']=$item->getBar();}// do something with $myArray}
As you can see in this example, the array $myArray is initialized the first
time when the foreach loop is entered. You can also see that the value of the
bar key is only written conditionally; thus, its value might result from a
previous iteration.
This might or might not be intended. To make your intention clear, your code
more readible and to avoid accidental bugs, we recommend to add an explicit
initialization $myArray=array() either outside or inside the foreach loop.
The variable $types 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;}
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.