<?php

namespace KupShop\SystemInspectionBundle\InspectionWriters;

use KupShop\SystemInspectionBundle\Exception\InspectionException;
use KupShop\SystemInspectionBundle\InspectionWriters\MessageTypes\ComposerMissingMessage;
use KupShop\SystemInspectionBundle\InspectionWriters\MessageTypes\HtmlDataMessage;
use KupShop\SystemInspectionBundle\InspectionWriters\MessageTypes\SimpleMessage;
use KupShop\SystemInspectionBundle\InspectionWriters\MessageTypes\StuckOrdersMessage;

class ExceptionWriter extends InspectionWriter
{
    protected $exceptions = [];

    public function visitComposerMissing(ComposerMissingMessage $message)
    {
        $this->exceptions[] = $message->getMessage();
    }

    public function visitStuckOrders(StuckOrdersMessage $message)
    {
        $this->exceptions[] = $message->getMessage();
    }

    public function visitSimple(SimpleMessage $message)
    {
        $this->exceptions[] = $message->getMessage();
    }

    public function visitHtmlData(HtmlDataMessage $message)
    {
        $this->exceptions[] = $message->getMessage();
    }

    public function end()
    {
        if ($this->exceptions) {
            throw new InspectionException(implode("\n", $this->exceptions));
        }
    }
}
