Sunday, May 21, 2017

Worst rated PHP Operations declared by Scrutinizer

I use scrutinizer to analyse my code, and I get a function declared:

Worst rated PHP Operations

This is the function:

/**
 * Insert Empty Fighters in an homogeneous way.
 *
 * @param Collection $fighters
 * @param Collection $byeGroup
 *
 * @return Collection
 */
private function insertByes(Collection $fighters, Collection $byeGroup)
{
    $bye = count($byeGroup) > 0 ? $byeGroup[0] : [];
    $sizeFighters = count($fighters);
    $sizeByeGroup = count($byeGroup);

    $frequency = $sizeByeGroup != 0
        ? (int)floor($sizeFighters / $sizeByeGroup)
        : -1;

    // Create Copy of $competitors
    $newFighters = new Collection();
    $count = 0;
    $byeCount = 0;
    foreach ($fighters as $fighter) {
        if ($frequency != -1 && $count % $frequency == 0 && $byeCount < $sizeByeGroup) {
            $newFighters->push($bye);
            $byeCount++;
        }
        $newFighters->push($fighter);
        $count++;
    }

    return $newFighters;
}

What this function is doing is trying to insert Empty Fighters in a regular / homogeneous way

But for me, this method seems quite OK, what am I not seeing?

Any better way to achieve it???



via Juliatzin del Toro

Advertisement