The expression return array_rand($array) could return the type array which is incompatible with the type-hinted return integer|string. Consider adding an additional type-check to rule them out.
Loading history...
22
}
23
24
1
private function generateRandomValueStandardNormalDistribution(int $min, int $max): int
25
{
26
1
$mean = (int)(($min + $max) / 2); // MW
27
1
$stdDeviation = (int) ($mean / 2.5); // FWHM
28
29
do {
30
1
$value = random_int($min, $max);
31
1
$probability = exp(-0.5 * (($value - $mean) / $stdDeviation) ** 2); // normal distribution
In this branch, the function will implicitly return null which is incompatible with the type-hinted return integer. Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type.
Let?s take a look at an example:
interfaceReturnsInt{publicfunctionreturnsIntHinted():int;}classMyClassimplementsReturnsInt{publicfunctionreturnsIntHinted():int{if(foo()){return123;}// here: null is implicitly returned}}