<?php

/**
 * Validation object
 *
 * Standard: PSR-2
 *
 * @link http://www.php-fig.org/psr/psr-2 Full Documentation
 */

defined('ABSPATH') || defined('DUPXABSPATH') || exit;

use Duplicator\Installer\Core\Params\PrmMng;

class DUPX_Validation_test_db_prefix_too_long extends DUPX_Validation_abstract_item
{
    /** @var string */
    protected $errorMessage = '';

    protected function runTest(): int
    {
        if (DUPX_Validation_database_service::getInstance()->skipDatabaseTests()) {
            return self::LV_SKIP;
        }

        DUPX_Validation_database_service::getInstance()->setSkipOtherTests(true);
        if (DUPX_Validation_database_service::getInstance()->checkDbPrefixTooLong($this->errorMessage)) {
            DUPX_Validation_database_service::getInstance()->setSkipOtherTests(false);
            return self::LV_PASS;
        } else {
            return self::LV_FAIL;
        }
    }

    public function getTitle(): string
    {
        return 'Prefix too long';
    }

    protected function failContent()
    {
        return dupxTplRender('parts/validation/database-tests/db-prefix-too-long', [
            'isOk'                 => false,
            'errorMessage'         => $this->errorMessage,
            'tooLongNewTableNames' => DUPX_Validation_database_service::getInstance()->getTooLongNewTableNames(),
        ], false);
    }

    protected function passContent()
    {
        return dupxTplRender('parts/validation/database-tests/db-prefix-too-long', [
            'isOk'                 => true,
            'errorMessage'         => $this->errorMessage,
            'tooLongNewTableNames' => DUPX_Validation_database_service::getInstance()->getTooLongNewTableNames(),
        ], false);
    }
}
