<commit_before><?php

/*
 * This file is part of Blogit.
 *
 * (c) Jong <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Jrean\Blogit\Document;

use Jrean\Blogit\Parser\ParserInterface;

abstract class AbstractDocument
{
    /**
     * Parser instance.
     *
     * @var \Jrean\Blogit\Parser\ParserInterface
     */
    protected $parser;

    /**
     * Document filename.
     *
     * @var string
     */
    protected $filename;

    /**
     * Document filepath.
     *
     * @var string
     */
    protected $path;

    /**
     * Document sha.
     *
     * @var string
     */
    protected $sha;

    /**
     * Document url.
     *
     * @var string
     */
    protected $url;

    /**
     * Document html url.
     *
     * @var string
     */
    protected $htmlUrl;

    /**
     * Document Git url.
     *
     * @var string
     */
    protected $gitUrl;

    /**
     * Document downlowd url.
     *
     * @var string
     */
    protected $downloadUrl;

    /**
     * Document creation date.
     *
     * @var string
     */
    protected $createdAt;

    /**
     * Document last udpate date.
     *
     * @var string
     */
    protected $updatedAt;

    /**
     * Document content.
     *
     * @var string base64 encoded
     */
    protected $content;

    /**
     * Document commit(s).
     *
     * @var array
     */
    protected $commits;

    /**
     * Create a new Document instance.
     *
     * @param \Jrean\Blogit\Parser\ParserInterface $parser
     * @param array $metadata
     * @param array $commits
     */
    public function __construct(ParserInterface $parser, array $metadata, array $commits)
    {
        $this->parser      = $parser;

        $this->filename    = $metadata['name'];
        $this->path        = $metadata['path'];
        $this->sha         = $metadata['sha'];
        $this->url         = $metadata['url'];
        $this->htmlUrl     = $metadata['html_url'];
        $this->gitUrl      = $metadata['git_url'];
        $this->downloadUrl = $metadata['download_url'];
        $this->content     = $metadata['content'];
        $this->commits     = $commits;

        $this
            ->setCreatedAt($commits)
            ->setUpdatedAt($commits);
    }

    /**
     * Get the document contributor(s).
     *
     * @return array
     */
    public function getContributors()
    {
        $contributors = [];
        foreach($this->commits as $commit) {
            $commiter = array_get($commit, 'author.login');
            if ( ! array_has($contributors, $commiter)) {
                $contributors[] = [
                    'name'       => $commiter,
                    'avatar_url' => array_get($commit, 'author.avatar_url'),
                    'html_url'   => array_get($commit, 'author.html_url')
                ];
            }
        }
        return $contributors;
    }

    /**
     * Format date.
     *
     * @param  string $date
     * @param  string $format
     * @return string
     */
    private function formatDate($date, $format = 'Y-m-d H:i:s')<commit_msg>Refactor<commit_after><?php

/*
 * This file is part of Blogit.
 *
 * (c) Jong <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Jrean\Blogit\Document;

use Jrean\Blogit\Parser\ParserInterface;

abstract class AbstractDocument
{
    /**
     * Parser instance.
     *
     * @var \Jrean\Blogit\Parser\ParserInterface
     */
    protected $parser;

    /**
     * Document filename.
     *
     * @var string
     */
    protected $filename;

    /**
     * Document filepath.
     *
     * @var string
     */
    protected $path;

    /**
     * Document sha.
     *
     * @var string
     */
    protected $sha;

    /**
     * Document url.
     *
     * @var string
     */
    protected $url;

    /**
     * Document html url.
     *
     * @var string
     */
    protected $htmlUrl;

    /**
     * Document Git url.
     *
     * @var string
     */
    protected $gitUrl;

    /**
     * Document downlowd url.
     *
     * @var string
     */
    protected $downloadUrl;

    /**
     * Document creation date.
     *
     * @var string
     */
    protected $createdAt;

    /**
     * Document last udpate date.
     *
     * @var string
     */
    protected $updatedAt;

    /**
     * Document content.
     *
     * @var string base64 encoded
     */
    protected $content;

    /**
     * Document commit(s).
     *
     * @var array
     */
    protected $commits;

    /**
     * Create a new Document instance.
     *
     * @param \Jrean\Blogit\Parser\ParserInterface $parser
     * @param array $metadata
     * @param array $commits
     */
    public function __construct(ParserInterface $parser, array $metadata, array $commits)
    {
        $this->parser      = $parser;

        $this->filename    = $metadata['name'];
        $this->path        = $metadata['path'];
        $this->sha         = $metadata['sha'];
        $this->url         = $metadata['url'];
        $this->htmlUrl     = $metadata['html_url'];
        $this->gitUrl      = $metadata['git_url'];
        $this->downloadUrl = $metadata['download_url'];
        $this->content     = $metadata['content'];
        $this->commits     = $commits;

        $this
            ->setCreatedAt($commits)
            ->setUpdatedAt($commits);
    }

    /**
     * Get the document contributor(s).
     *
     * @return array
     */
    public function getContributors()
    {
        $contributors = [];
        foreach($this->commits as $commit) {
            $commiter = array_get($commit, 'author.login');
            if ( ! array_has($contributors, $commiter)) {
                $contributors[$commiter] = [
                    'name'       => $commiter,
                    'avatar_url' => array_get($commit, 'author.avatar_url'),
                    'html_url'   => array_get($commit, 'author.html_url')
                ];
            }
        }
        return $contributors;
    }

    /**
     * Format date.
     *
     * @param  string $date
     * @param  string $format
     * @return string
     */
    private function formatDate($date, $format = 'Y-m-d H:i:s')
{'fraction_non_alphanumeric': 0.1361198738170347, 'fraction_numerical': 0.0006309148264984228, 'mean_word_length': 1.6062474311549528, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '908422', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1870, 'n_words': 413}