<?php

declare(strict_types=1);

namespace Tricks\PackageHelper;

final class Helper implements HelperContract
{
    public static function trimmedResponse(string $command): string
    {
        $return = self::execute($command);

        if (is_null($return)) {
            self::fail("Command `$command` returns null instead of a string.");
        }
        return trim($return);
    }

    public static function execute(string $command): ?string
    {
        $return = shell_exec($command);
        if ($return === false) {
            self::fail("Command `$command` was not successful.");
        }
        return $return;
    }

    public static function fail(string $reason): never
    {
        exit("\033[41m $reason \n\033[0m");
    }
}
