<commit_before><?php

namespace Gdbots\Pbjc\Generator;

use Gdbots\Pbjc\Schema;
use Gdbots\Pbjc\Twig\Extension\ClassExtension;

/**
 * Generator is the base class for all generators.
 */
abstract class Generator
{
    /**
     * The directory to look for templates.
     */
    const SKELETON_DIR = __DIR__.'/../Resources/skeleton/';

    /**
     * The extension to use for written files.
     *
     * @var string
     */
    protected $extension = '.php';

    /** @var string */
    protected $prefix = '';

    /** @var string */
    protected $template = '';

    /** @var Schema */
    protected $schema;

    /** @var bool */
    protected $isLatest = false;

    /**
     * Sets the extension to use when writing files to disk.
     *
     * @param string $extension
     *
     * @return void
     */
    public function setExtension($extension)
    {
        $this->extension = $extension;
    }

    /**
     * Sets a file prefix.
     *
     * @param string $prefix
     *
     * @return void
     */
    public function setPrefix($prefix)
    {
        $this->prefix = $prefix;
    }

    /**
     * Sets a template.
     *
     * @param string $template
     *
     * @return void
     */
    public function setTemplate($template)
    {
        $this->template = $template;
    }

    /**
     * Generates and writes files for the given yaml file.
     *
     * @param Schema $schema
     * @param string $output
     * @param bool   $isLatest
     *
     * @return void
     */
    public function generate(Schema $schema, $output, $isLatest = false)
    {
        $this->schema = $schema;
        $this->isLatest = $isLatest;

        $this->renderFile(
            $this->getTemplate(),
            $this->getTarget($output),
            $this->getParameters(),
            empty($output)
        );
    }

    /**
     * @return bool
     */
    public function isOnlyLatest()
    {
        return true;
    }

    /**
     * @return string
     */
    protected function getTemplate()
    {
        return $this->template;
    }

    /**
     * @param string $output
     *
     * @return string
     */
    protected function getTarget($output)
    {
        return sprintf('%s/%s%s%s', $output, $this->getTargetFilename(), $this->prefix, $this->extension);
    }

    /**
     * @return string
     */
    protected function getTargetFilename()
    {
        return $this->schema->getClassName();
    }

    /**
     * @return array
     */
    protected function getParameters()
    {
        return [
            'schema' => $this->schema,
            'prefix' => $this->prefix
        ];
    }

    /**<commit_msg>Set file sub-directories based on the schema-id curie value<commit_after><?php

namespace Gdbots\Pbjc\Generator;

use Gdbots\Pbjc\Schema;
use Gdbots\Pbjc\Twig\Extension\ClassExtension;

/**
 * Generator is the base class for all generators.
 */
abstract class Generator
{
    /**
     * The directory to look for templates.
     */
    const SKELETON_DIR = __DIR__.'/../Resources/skeleton/';

    /**
     * The extension to use for written files.
     *
     * @var string
     */
    protected $extension = '.php';

    /** @var string */
    protected $prefix = '';

    /** @var string */
    protected $template = '';

    /** @var Schema */
    protected $schema;

    /** @var bool */
    protected $isLatest = false;

    /**
     * Sets the extension to use when writing files to disk.
     *
     * @param string $extension
     *
     * @return void
     */
    public function setExtension($extension)
    {
        $this->extension = $extension;
    }

    /**
     * Sets a file prefix.
     *
     * @param string $prefix
     *
     * @return void
     */
    public function setPrefix($prefix)
    {
        $this->prefix = $prefix;
    }

    /**
     * Sets a template.
     *
     * @param string $template
     *
     * @return void
     */
    public function setTemplate($template)
    {
        $this->template = $template;
    }

    /**
     * Generates and writes files for the given yaml file.
     *
     * @param Schema $schema
     * @param string $output
     * @param bool   $isLatest
     *
     * @return void
     */
    public function generate(Schema $schema, $output, $isLatest = false)
    {
        $this->schema = $schema;
        $this->isLatest = $isLatest;

        $this->renderFile(
            $this->getTemplate(),
            $this->getTarget($output),
            $this->getParameters(),
            empty($output)
        );
    }

    /**
     * @return bool
     */
    public function isOnlyLatest()
    {
        return true;
    }

    /**
     * @return string
     */
    protected function getTemplate()
    {
        return $this->template;
    }

    /**
     * @param string $output
     *
     * @return string
     */
    protected function getTarget($output)
    {
        return sprintf('%s/%s/%s%s%s',
            $output,
            str_replace(':', '/', $this->schema->getId()->getCurie()),
            $this->getTargetFilename(),
            $this->prefix,
            $this->extension
        );
    }

    /**
     * @return string
     */
    protected function getTargetFilename()
    {
        return $this->schema->getClassName();
    }

    /**
     * @return array
     */
    protected function getParameters()
    {
        return [
            'schema' => $this->schema,
            'prefix' => $this->prefix
        ];
    }

    /**
{'fraction_non_alphanumeric': 0.13743815283122596, 'fraction_numerical': 0.0, 'mean_word_length': 1.6754901960784314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '7458204', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1592, 'n_words': 378}