<commit_before><?php

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

namespace cloak\reporter;

use cloak\reporter\Reportable;
use cloak\Result;
use cloak\result\File;
use cloak\writer\FileWriter;
use cloak\event\StartEventInterface;
use cloak\event\StopEventInterface;


/**
 * Class MarkdownReporter
 * @package cloak\reporter
 */
class MarkdownReporter implements ReporterInterface
{

    use Reportable;

    /**
     * @var \cloak\writer\FileWriter
     */
    private $reportWriter;

    /**
     * @param string $outputFilePath
     */
    public function __construct($outputFilePath)
    {
        $this->reportWriter = new FileWriter($outputFilePath);
    }

    /**
     * @param StartEventInterface $event
     */
    public function onStart(StartEventInterface $event)
    {
    }

    /**
     * @param StopEventInterface $event
     */
    public function onStop(StopEventInterface $event)
    {
        $this->writeMarkdownReport($event->getResult());
    }

    /**
     * @param Result $result
     */
    private function writeMarkdownReport(Result $result)
    {
        $this->writeTitle();
        $this->writeDescription();
        $this->writeResult($result);
    }

    private function writeTitle()
    {
        $this->reportWriter->writeLine('# Code Coverage Report');
        $this->reportWriter->writeLine('');
    }

    private function writeDescription()
    {
        $this->reportWriter->writeLine('Generator: cloak  ');
        $this->reportWriter->writeLine('Generated at: 2014-07-10 00:00:00  ');
        $this->reportWriter->writeLine('');
    }

    private function writeResultHeader()
    {
        $this->reportWriter->writeLine('## Result');
        $this->reportWriter->writeLine('');

        $this->reportWriter->writeLine('| No. | File | Line | Coverage |');
        $this->reportWriter->writeLine('|:-|:-|-:|-:|');
    }

    private function writeResult(Result $result)
    {
        $this->writeResultHeader();

        $files = $result->getFiles();

        foreach ($files as $key => $file) {
            $orderNumber = $key + 1;
            $this->writeFileResult($orderNumber, $file);
        }
    }

    private function writeFileResult($orderNumber, File $file)
    {

        $lineResult = sprintf("%2d/%2d",
            $file->getExecutedLineCount(),
            $file->getExecutableLineCount()
        );

        $coverageResult = sprintf('%6.2f%%', $file->getCodeCoverage()->value());

        $parts = [
            $orderNumber,
            $file->getRelativePath(getcwd()),
            $lineResult,
            $coverageResult
        ];

        $record = '|' . implode('|', $parts) . '|';

        $this->reportWriter->writeLine($record);
    }

}
<commit_msg>Refactaring<commit_after><?php

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

namespace cloak\reporter;

use cloak\reporter\Reportable;
use cloak\Result;
use cloak\result\File;
use cloak\writer\FileWriter;
use cloak\event\StartEventInterface;
use cloak\event\StopEventInterface;
use PhpCollection\Sequence;


/**
 * Class MarkdownReporter
 * @package cloak\reporter
 */
class MarkdownReporter implements ReporterInterface
{

    use Reportable;

    /**
     * @var \cloak\writer\FileWriter
     */
    private $reportWriter;

    /**
     * @param string $outputFilePath
     */
    public function __construct($outputFilePath)
    {
        $this->reportWriter = new FileWriter($outputFilePath);
    }

    /**
     * @param StartEventInterface $event
     */
    public function onStart(StartEventInterface $event)
    {
    }

    /**
     * @param StopEventInterface $event
     */
    public function onStop(StopEventInterface $event)
    {
        $this->writeMarkdownReport($event->getResult());
    }

    /**
     * @param Result $result
     */
    private function writeMarkdownReport(Result $result)
    {
        $this->writeTitle();
        $this->writeDescription();
        $this->writeResult($result);
    }

    private function writeTitle()
    {
        $this->reportWriter->writeLine('# Code Coverage Report');
        $this->reportWriter->writeLine('');
    }

    private function writeDescription()
    {
        $this->reportWriter->writeLine('Generator: cloak  ');
        $this->reportWriter->writeLine('Generated at: 2014-07-10 00:00:00  ');
        $this->reportWriter->writeLine('');
    }

    private function writeResult(Result $result)
    {
        $this->writeResultHeader();
        $this->writeFilesResultHeader();
        $this->writeFilesResult($result->getFiles());
    }

    private function writeResultHeader()
    {
        $this->reportWriter->writeLine('## Result');
        $this->reportWriter->writeLine('');
    }

    private function writeFilesResultHeader()
    {
        $this->reportWriter->writeLine('| No. | File | Line | Coverage |');
        $this->reportWriter->writeLine('|:-|:-|-:|-:|');
    }

    /**
     * @param Sequence $files
     */
    private function writeFilesResult(Sequence $files)
    {
        foreach ($files as $key => $file) {
            $orderNumber = $key + 1;
            $this->writeFileResult($orderNumber, $file);
        }
    }

    /**
     * @param int $orderNumber
     * @param File $file
     */
    private function writeFileResult($orderNumber, File $file)
    {

        $lineResult = sprintf("%2d/%2d",
            $file->getExecutedLineCount(),
            $file->getExecutableLineCount()
        );

        $coverageResult = sprintf('%6.2f%%', $file->getCodeCoverage()->value());

        $parts = [
            $orderNumber,
            $file->getRelativePath(getcwd()),
            $lineResult,
            $coverageResult
        ];

        $record = '|' . implode('|', $parts) . '|';

        $this->reportWriter->writeLine($record);
    }

}

{'fraction_non_alphanumeric': 0.1472970738965118, 'fraction_numerical': 0.006282030087617788, 'mean_word_length': 2.4492588369441277, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 81, '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': '2956364', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1727, 'n_words': 338}