<commit_before><?php
namespace nochso\Phormat\CLI;

use Aura\Cli\CliFactory;
use Aura\Cli\Context\OptionFactory;
use Aura\Cli\Status;
use Aura\Cli\Stdio;
use Aura\Cli\Stdio\Formatter;
use Humbug\SelfUpdate\Strategy\GithubStrategy;
use Humbug\SelfUpdate\Updater;
use nochso\Omni\VersionInfo;
use nochso\Phormat\Parser\NodeSorter;

class Application {
	/**
	 * @var \Aura\Cli\Context
	 */
	private $context;
	/**
	 * @var \nochso\Phormat\CLI\Stdio
	 */
	private $stdio;
	/**
	 * @var VersionInfo
	 */
	private $version;

	public function __construct($version) {
		$this->version = $version;
		$cliFactory = new CliFactory();
		$this->context = $cliFactory->newContext($GLOBALS);
		$this->stdio = new \nochso\Phormat\CLI\Stdio(
			new Handle('php://stdin', 'r'),
			new Handle('php://stdout', 'w+'),
			new Handle('php://stderr', 'w+'),
			new Formatter()
		);
		$this->opt = $this->context->getopt($this->getOptions());
	}

	public function run() {
		$this->showVersion();
		if ($this->opt->get('--version')) {
			exit(Status::SUCCESS);
		}
		if ($this->opt->get('--help')) {
			$this->showHelp();
			return;
		}
		if ($this->opt->get('--self-update')) {
			$this->selfUpdate();
			exit(Status::SUCCESS);
		}
		$errors = $this->opt->getErrors();
		$paths = array_filter(
			$this->opt->get(),
			function ($key) {
				return is_int($key) && $key > 0;
			},
			ARRAY_FILTER_USE_KEY
		);
		$job = $this->prepareJob($paths, $errors);
		$job->run();
		exit(Status::SUCCESS);
	}

	/**
	 * @param $paths
	 * @param $errors
	 *
	 * @return \nochso\Phormat\CLI\FormatJob
	 */
	private function prepareJob($paths, $errors) {
		$job = new FormatJob($this->stdio);<commit_msg>fix: Explicitly exit with success after --help<commit_after><?php
namespace nochso\Phormat\CLI;

use Aura\Cli\CliFactory;
use Aura\Cli\Context\OptionFactory;
use Aura\Cli\Status;
use Aura\Cli\Stdio;
use Aura\Cli\Stdio\Formatter;
use Humbug\SelfUpdate\Strategy\GithubStrategy;
use Humbug\SelfUpdate\Updater;
use nochso\Omni\VersionInfo;
use nochso\Phormat\Parser\NodeSorter;

class Application {
	/**
	 * @var \Aura\Cli\Context
	 */
	private $context;
	/**
	 * @var \nochso\Phormat\CLI\Stdio
	 */
	private $stdio;
	/**
	 * @var VersionInfo
	 */
	private $version;

	public function __construct($version) {
		$this->version = $version;
		$cliFactory = new CliFactory();
		$this->context = $cliFactory->newContext($GLOBALS);
		$this->stdio = new \nochso\Phormat\CLI\Stdio(
			new Handle('php://stdin', 'r'),
			new Handle('php://stdout', 'w+'),
			new Handle('php://stderr', 'w+'),
			new Formatter()
		);
		$this->opt = $this->context->getopt($this->getOptions());
	}

	public function run() {
		$this->showVersion();
		if ($this->opt->get('--version')) {
			exit(Status::SUCCESS);
		}
		if ($this->opt->get('--help')) {
			$this->showHelp();
			exit(Status::SUCCESS);
		}
		if ($this->opt->get('--self-update')) {
			$this->selfUpdate();
			exit(Status::SUCCESS);
		}
		$errors = $this->opt->getErrors();
		$paths = array_filter(
			$this->opt->get(),
			function ($key) {
				return is_int($key) && $key > 0;
			},
			ARRAY_FILTER_USE_KEY
		);
		$job = $this->prepareJob($paths, $errors);
		$job->run();
		exit(Status::SUCCESS);
	}

	/**
	 * @param $paths
	 * @param $errors
	 *
	 * @return \nochso\Phormat\CLI\FormatJob
	 */
	private function prepareJob($paths, $errors) {
		$job = new FormatJob($this->stdio);
{'fraction_non_alphanumeric': 0.2012448132780083, 'fraction_numerical': 0.0005927682276229994, 'mean_word_length': 3.7202797202797204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '5251365', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1240, 'n_words': 217}