Skip to content

filterBestVotedImage returns null when all images have voteAverage 0 #164

@Fluxlicious

Description

@Fluxlicious

There's a problem with the filter filterBestVotedImage(). If all the images it filter through have a voteAverage of 0, then it will return null whereas it should return the first occurrence of a 0 value.

Possible fix is to set the $voteAverage to -1 as initial value like this:

    public function filterBestVotedImage()
    {
        $currentImage = null;
        $voteAverage  = -1;

        /**
         * @var $image Image
         */
        foreach ($this->data as $image) {
            if ($image->getVoteAverage() > $voteAverage) {
                $voteAverage  = $image->getVoteAverage();
                $currentImage = $image;
            }
        }

        return $currentImage;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions