<?php
/**
 * Created by PhpStorm.
 * User: peroperje
 * Date: 13.5.16.
 * Time: 08.46
 */

namespace Ezypay\Validation\Validator;
use Ezypay\Contract\IValidator;

/**
 * Class NotEmptyString
 *
 * Validate empty string
 *
 * @package Ezypay\Validation
 */
class NotEmptyString implements IValidator
{
    /**
     * @var string string The string for validation
     */
    protected $string;
    /**
     * @var $errorContainer string The container for error message
     */
    protected $errorContainer;
    /**
     * @var $errorMessage string The error message
     */
    protected $errorMessage;

    /**
     * NotEmptyString constructor.
     *
     * @param $string string
     * @param $errorMessage string
     */
    public function __construct($string,$errorMessage)
    {
        $this->string = $string;
        $this->errorContainer = $errorMessage;
    }

    /**
     * Check is provided data valid
     *
     * @return bool
     */
    public function validate()
    {
        if (!empty($this->string)) {
            return true;
        }
        $this->errorMessage = $this->errorContainer;
        return false;
    }

    /**
     * Retrun error string or null
     *
     * @return string | null
     */
    public function getFormattedError()
    {
        return $this->errorMessage;
    }
}
