<commit_before><?php

namespace Lmc\Steward\Publisher;

class XmlPublisher extends AbstractPublisher
{
    /** @var string */
    protected $fileName;

    /** @var resource */
    protected $fileHandle;

    /**
     * @param string $environment
     * @param string $jobName
     * @param int $buildNumber
     */
    public function __construct($environment, $jobName, $buildNumber)
    {
        $this->fileName = realpath(__DIR__ . '/../../logs') . '/results.xml';
    }

    /**
     * Set file name. Mostly usable for testing to override the default.
     * @param string $fileName
     */
    public function setFileName($fileName)
    {
        $this->fileName = $fileName;
    }

    /**
     * Clean the file with all previous results (if exists).
     */
    public function clean()
    {
        if (file_exists($this->fileName)) {
            unlink($this->fileName);
        }
    }

    /**<commit_msg>Auto-create directory for logs if it does not exist<commit_after><?php

namespace Lmc\Steward\Publisher;

class XmlPublisher extends AbstractPublisher
{
    /** @var string */
    protected $fileName;

    /** @var resource */
    protected $fileHandle;

    /**
     * @param string $environment
     * @param string $jobName
     * @param int $buildNumber
     */
    public function __construct($environment, $jobName, $buildNumber)
    {
        $fileDir = __DIR__ . '/../../logs';
        if (!is_dir($fileDir)) {
            mkdir($fileDir, 0755);
        }

        $this->fileName =  realpath($fileDir) . '/results.xml';
    }

    /**
     * Set file name. Mostly usable for testing to override the default.
     * @param string $fileName
     */
    public function setFileName($fileName)
    {
        $this->fileName = $fileName;
    }

    /**
     * Clean the file with all previous results (if exists).
     */
    public function clean()
    {
        if (file_exists($this->fileName)) {
            unlink($this->fileName);
        }
    }

    /**
{'fraction_non_alphanumeric': 0.13313161875945537, 'fraction_numerical': 0.002017145738779627, 'mean_word_length': 2.104851330203443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5261686', 'n_tokens_mistral': 580, 'n_tokens_neox': 566, 'n_words': 148}