Choice.php 1.33 KB
<?php

namespace FootyRoom\Core\Poll;

use FootyRoom\Core\CoreException;

/**
 * Choice value object.
 */
class Choice
{
    /**
     * @var int Id of this choice, uniqie within the poll only
     */
    protected $id;

    /**
     * @var string Text value representing this choice
     */
    protected $text;

    /**
     * @var string URL to the image representing this choice
     */
    protected $image;

    /**
     * Constructor.
     *
     * @param int $id
     * @param string $text
     * @param string $image
     *
     * @throws \FootyRoom\Core\CoreException
     */
    public function __construct($id, $text, $image)
    {
        $this->id = $id;
        $this->text = $text;
        $this->image = $image;

        if (!strlen($this->text) && !strlen($this->image)) {
            throw new CoreException('Either text or image of a choice must be set.');
        }
    }

    /**
     * Gets the value of id.
     *
     * @return int id of this choice of poll.
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Gets the value of text.
     *
     * @return string|int
     */
    public function getText()
    {
        return $this->text;
    }

    /**
     * Gets the value of image.
     *
     * @return string
     */
    public function getImage()
    {
        return $this->image;
    }
}