FlagsReport.php 1.2 KB
<?php

namespace FootyRoom\Queries\Comment;

class FlagsReport
{
    /**
     * @var int
     */
    public $commentId;

    /**
     * @var \FootyRoom\Queries\Comment\Comment
     */
    public $comment;

    /**
     * @var string[] List of usernames who reported this flag.
     */
    public $spam;

    /**
     * @var string[] List of usernames who reported this flag.
     */
    public $rude;

    /**
     * @var string[] List of usernames who reported this flag.
     */
    public $broken;

    /**
     * @var int
     */
    public $total;

    /**
     * @var string
     */
    public $url;

    /**
     * @var \FootyRoom\Queries\Post\Post
     */
    public $post;

    /**
     * Gets the name of the flag raised by user.
     *
     * @param string $username
     *
     * @return string|null
     */
    public function getFlagByUsername($username): ?string
    {
        foreach (['spam', 'rude', 'broken'] as $flagName) {
            if (!$this->$flagName) {
                continue;
            }

            foreach ($this->$flagName as $reporter) {
                if ($reporter === $username) {
                    return $flagName;
                }
            }
        }

        return null;
    }
}