<commit_before><?hh //strict

/**
 * This file is part of hhpack\typechecker package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace hhpack\typechecker;

use hhpack\typechecker\check\Result;
use hhpack\process\Process;
use RuntimeException;


final class TypeCheckerClient implements ClientBehavior
{

    const PROGRAM = 'hh_client';

    public function __construct(
        private string $cwd = (string) getcwd()
    )
    {
    }

    public async function version() : Awaitable<Version>
    {
        $result = await Process::exec( $this->command('', [ '--version' ]), $this->cwd );
        $version = (string) $result->getStdout();

        return trim($version);
    }

    public async function init() : Awaitable<ConfigurationPath>
    {
        $path = realpath($this->cwd) . '/.hhconfig';

        if (touch($path) === false) {
            throw new RuntimeException('Failed to generate .hhconfig');
        }

        return $path;
    }

    public async function start() : Awaitable<void>
    {
        await Process::exec( $this->command('start'), $this->cwd );
    }

    public async function stop() : Awaitable<void>
    {
        await Process::exec( $this->command('stop'), $this->cwd );
    }

    public async function restart() : Awaitable<void>
    {
        await Process::exec( $this->command('restart'), $this->cwd );
    }

    public async function check() : Awaitable<Result>
    {
        $result = await Process::exec( $this->command('check', [ '--json' ]), $this->cwd);
        return Result::fromString((string) $result->getStderr());
    }

    private function command(string $command, Traversable<string> $args = []) : string
    {
        $builder = Set {};
        $builder->add('%s %s %s');
        $builder->addAll([ static::PROGRAM, $command, implode(' ', $args) ]);

        return call_user_func_array('sprintf', $builder->toValuesArray());
    }

}<commit_msg>Update for process package<commit_after><?hh //strict

/**
 * This file is part of hhpack\typechecker package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace hhpack\typechecker;

use hhpack\typechecker\check\Result;
use hhpack\process;
use hhpack\process\ExecOptions;
use RuntimeException;


final class TypeCheckerClient implements ClientBehavior
{

    const PROGRAM = 'hh_client';

    public function __construct(
        private string $cwd = (string) getcwd()
    )
    {
    }

    public async function version() : Awaitable<Version>
    {
        $options = new ExecOptions($this->cwd);

        $result = await process\exec( $this->command('', [ '--version' ]), $options );
        $version = (string) $result->stdout();

        return trim($version);
    }

    public async function init() : Awaitable<ConfigurationPath>
    {
        $path = realpath($this->cwd) . '/.hhconfig';

        if (touch($path) === false) {
            throw new RuntimeException('Failed to generate .hhconfig');
        }

        return $path;
    }

    public async function start() : Awaitable<void>
    {
        $options = new ExecOptions($this->cwd);
        await process\exec( $this->command('start'), $options );
    }

    public async function stop() : Awaitable<void>
    {
        $options = new ExecOptions($this->cwd);
        await process\exec( $this->command('stop'), $options );
    }

    public async function restart() : Awaitable<void>
    {
        $options = new ExecOptions($this->cwd);
        await process\exec( $this->command('restart'), $options );
    }

    public async function check() : Awaitable<Result>
    {
        $options = new ExecOptions($this->cwd);

        $result = await process\exec( $this->command('check', [ '--json' ]), $options);
        return Result::fromString((string) $result->stderr());
    }

    private function command(string $command, Traversable<string> $args = []) : string
    {
        $builder = Set {};
        $builder->add('%s %s %s');
        $builder->addAll([ static::PROGRAM, $command, implode(' ', $args) ]);

        return call_user_func_array('sprintf', $builder->toValuesArray());
    }

}
{'fraction_non_alphanumeric': 0.15128205128205127, 'fraction_numerical': 0.0, 'mean_word_length': 2.8244206773618536, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7427433', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1272, 'n_words': 324}