public function formatErrors(
		AnalysisResult $analysisResult,
		OutputStyle $style
	): int
	{
		$style->writeln('<?xml version="1.0" encoding="UTF-8"?>');
		$style->writeln('<checkstyle>');

		foreach ($this->groupByFile($analysisResult) as $relativeFilePath => $errors) {
			$style->writeln(sprintf(
				'<file name="%s">',
				$this->escape($relativeFilePath)
			));

			foreach ($errors as $error) {
				$style->writeln(sprintf(
					'  <error line="%d" column="1" severity="error" message="%s" />',
					$this->escape((string) $error->getLine()),
					$this->escape((string) $error->getMessage())
				));
			}
			$style->writeln('</file>');
		}

		$notFileSpecificErrors = $analysisResult->getNotFileSpecificErrors();

		if (count($notFileSpecificErrors) > 0) {
			$style->writeln('<file>');

			foreach ($notFileSpecificErrors as $error) {
				$style->writeln(sprintf('  <error severity="error" message="%s" />', $this->escape($error)));
			}

			$style->writeln('</file>');
		}

		$style->writeln('</checkstyle>');

		return $analysisResult->hasErrors() ? 1 : 0;
	}