diff --git a/lib/PHPPeru/Exam/ExamInterface.php b/lib/PHPPeru/Exam/ExamInterface.php index 419b077..5523f05 100644 --- a/lib/PHPPeru/Exam/ExamInterface.php +++ b/lib/PHPPeru/Exam/ExamInterface.php @@ -1,35 +1,35 @@ - - * @todo add methods to the interface besides the ones used as examples - */ -interface ExamInterface -{ - /** - * Begins the exam. - * - * @throws BadMethodCallException if the exam can't be started - */ - public function start(); - - /** - * Aborts the exam. - * - * @throws BadMethodCallException if the exam can't be aborted - */ - public function abort(); - - /** - * Completes the exam - * - * @throws BadMethodCallException if the exam can't be completed - */ - public function complete(); + + * @todo add methods to the interface besides the ones used as examples + */ +interface ExamInterface extends Iterator +{ + /** + * Begins the exam. + * + * @throws BadMethodCallException if the exam can't be started + */ + public function start(); + + /** + * Aborts the exam. + * + * @throws BadMethodCallException if the exam can't be aborted + */ + public function abort(); + + /** + * Completes the exam + * + * @throws BadMethodCallException if the exam can't be completed + */ + public function complete(); } \ No newline at end of file diff --git a/lib/PHPPeru/Exam/SimpleExam.php b/lib/PHPPeru/Exam/SimpleExam.php index a2cdf0c..82ca9e5 100644 --- a/lib/PHPPeru/Exam/SimpleExam.php +++ b/lib/PHPPeru/Exam/SimpleExam.php @@ -1,134 +1,169 @@ - - * @todo eventually define if ".pre" or ".post" events should be used. - */ -class SimpleExam implements ExamInterface -{ - - const STATUS_NEW = 0; - const STATUS_STARTED = 1; - const STATUS_ABORTED = 2; - const STATUS_COMPLETED = 4; - - const EVENT_START = 'start'; - const EVENT_ABORT = 'abort'; - const EVENT_COMPLETE = 'complete'; - - /** - * Event dispatcher used internally to trigger events during lifecycle - * - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * Defines the current status of the exam - * - * @var type - */ - protected $status = self::STATUS_NEW; - - /** - * Default constructor, initializes events - */ - public function __construct() - { - $this->eventDispatcher = new EventDispatcher(); - } - - /** - * {@inheritdoc} - */ - public function start() - { - if (!$this->isNew()) { - throw new BadMethodCallException('Exam is not new'); - } - $this->status = self::STATUS_STARTED; - $this->eventDispatcher->dispatch(self::EVENT_START, new Event($this)); - } - - /** - * {@inheritdoc} - */ - public function abort() - { - if (!$this->isStarted()) { - throw new BadMethodCallException('Exam is not started'); - } - $this->status = self::STATUS_ABORTED; - $this->eventDispatcher->dispatch(self::EVENT_ABORT, new Event($this)); - } - - /** - * {@inheritdoc} - */ - public function complete() - { - if (!$this->isStarted()) { - throw new BadMethodCallException('Exam is not started'); - } - $this->status = self::STATUS_COMPLETED; - $this->eventDispatcher->dispatch(self::EVENT_COMPLETE, new Event($this)); - } - - /** - * Checks if the exam is new - * - * @return bool - */ - public function isNew() - { - return $this->status === self::STATUS_NEW; - } - - /** - * Checks if the exam has been started - * - * @return bool - */ - public function isStarted() - { - return $this->status === self::STATUS_STARTED; - } - - /** - * Checks if the exam has been aborted - * - * @return bool - */ - public function isAborted() - { - return $this->status === self::STATUS_ABORTED; - } - - /** - * Checks if the exam has been completed - * - * @return bool - */ - public function isCompleted() - { - return $this->status === self::STATUS_COMPLETED; - } - - /** - * Retrieves the associated event dispatcher - * - * @return EventDispatcherInterface - */ - public function getEventDispatcher() - { - return $this->eventDispatcher; - } + + * @todo eventually define if ".pre" or ".post" events should be used. + */ +class SimpleExam implements ExamInterface +{ + + const STATUS_NEW = 0; + const STATUS_STARTED = 1; + const STATUS_ABORTED = 2; + const STATUS_COMPLETED = 4; + + const EVENT_START = 'start'; + const EVENT_ABORT = 'abort'; + const EVENT_COMPLETE = 'complete'; + + /** + * Event dispatcher used internally to trigger events during lifecycle + * + * @var EventDispatcherInterface + */ + protected $eventDispatcher; + + /** + * Defines the current status of the exam + * + * @var type + */ + protected $status = self::STATUS_NEW; + + /** + * Default constructor, initializes events + */ + public function __construct() + { + $this->eventDispatcher = new EventDispatcher(); + } + + /** + * {@inheritdoc} + */ + public function start() + { + if (!$this->isNew()) { + throw new BadMethodCallException('Exam is not new'); + } + $this->status = self::STATUS_STARTED; + $this->eventDispatcher->dispatch(self::EVENT_START, new Event($this)); + } + + /** + * {@inheritdoc} + */ + public function abort() + { + if (!$this->isStarted()) { + throw new BadMethodCallException('Exam is not started'); + } + $this->status = self::STATUS_ABORTED; + $this->eventDispatcher->dispatch(self::EVENT_ABORT, new Event($this)); + } + + /** + * {@inheritdoc} + */ + public function complete() + { + if (!$this->isStarted()) { + throw new BadMethodCallException('Exam is not started'); + } + $this->status = self::STATUS_COMPLETED; + $this->eventDispatcher->dispatch(self::EVENT_COMPLETE, new Event($this)); + } + + /** + * Checks if the exam is new + * + * @return bool + */ + public function isNew() + { + return $this->status === self::STATUS_NEW; + } + + /** + * Checks if the exam has been started + * + * @return bool + */ + public function isStarted() + { + return $this->status === self::STATUS_STARTED; + } + + /** + * Checks if the exam has been aborted + * + * @return bool + */ + public function isAborted() + { + return $this->status === self::STATUS_ABORTED; + } + + /** + * Checks if the exam has been completed + * + * @return bool + */ + public function isCompleted() + { + return $this->status === self::STATUS_COMPLETED; + } + + /** + * Retrieves the associated event dispatcher + * + * @return EventDispatcherInterface + */ + public function getEventDispatcher() + { + return $this->eventDispatcher; + } + + /** + * {@inheritdoc} + */ + public function current() { + throw new BadMethodCallException('Not implemented'); + } + + /** + * {@inheritdoc} + */ + public function key() { + throw new BadMethodCallException('Not implemented'); + } + + /** + * {@inheritdoc} + */ + public function next() { + throw new BadMethodCallException('Not implemented'); + } + + /** + * {@inheritdoc} + */ + public function rewind() { + throw new BadMethodCallException('Not implemented'); + } + + /** + * {@inheritdoc} + */ + public function valid() { + throw new BadMethodCallException('Not implemented'); + } } \ No newline at end of file