<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console;

use PpPhp\Core\Platform\Console\Contracts\CommandInterface;

abstract class AbstractCommand implements CommandInterface
{
    protected function line(string $text = ''): void
    {
        echo $text . PHP_EOL;
    }

    protected function title(string $text): void
    {
        $this->line($text);
        $this->line(str_repeat('=', strlen($text)));
    }

    protected function table(array $rows): void
    {
        foreach ($rows as $row) {
            $this->line((string)$row);
        }
    }

    protected function json(array $data): void
    {
        $this->line(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
    }
}
