<commit_before><?php

namespace Backend\Modules\Pages\Domain\PageBlock;

use Backend\Core\Language\Language as BL;
use Common\Language;
use JsonSerializable;
use SpoonFilter;

final class Type implements JsonSerializable
{
    private const RICH_TEXT = 'rich_text';
    private const BLOCK = 'block';
    private const WIDGET = 'widget';
    private const USER_TEMPLATE = 'usertemplate';

    public const POSSIBLE_TYPES = [
        self::RICH_TEXT,
        self::BLOCK,
        self::WIDGET,
        self::USER_TEMPLATE,
    ];

    /** @var string */
    private $type;

    /**
     * @param string $type
     *
     * @throws InvalidPageBlockTypeException
     */
    public function __construct(string $type)
    {
        if (!in_array($type, self::POSSIBLE_TYPES, true)) {
            throw InvalidPageBlockTypeException::withType($type);
        }

        $this->type = $type;
    }

    public static function richText(): self
    {
        return new self(self::RICH_TEXT);
    }

    public static function block(): self
    {
        return new self(self::BLOCK);
    }

    public static function widget(): self
    {
        return new self(self::WIDGET);
    }

    public static function userTemplate(): self
    {
        return new self(self::USER_TEMPLATE);
    }

    public function __toString(): string
    {
        return $this->type;
    }

    public function jsonSerialize(): string
    {
        return (string) $this;
    }

    /**
     * @return self[]
     */
    public static function dropdownChoices(): array
    {
        return [
            SpoonFilter::ucfirst(Language::lbl('Editor')) => self::richText(),
            SpoonFilter::ucfirst(Language::lbl('Module')) => self::block(),
            SpoonFilter::ucfirst(Language::lbl('Widget')) => self::widget(),
            SpoonFilter::ucfirst(Language::lbl('UserTemplate')) => self::userTemplate(),
        ];
    }
}<commit_msg>Implement way to get label of the selected type<commit_after><?php

namespace Backend\Modules\Pages\Domain\PageBlock;

use Backend\Core\Language\Language as BL;
use Common\Language;
use JsonSerializable;
use RuntimeException;
use SpoonFilter;

final class Type implements JsonSerializable
{
    private const RICH_TEXT = 'rich_text';
    private const BLOCK = 'block';
    private const WIDGET = 'widget';
    private const USER_TEMPLATE = 'usertemplate';

    public const POSSIBLE_TYPES = [
        self::RICH_TEXT,
        self::BLOCK,
        self::WIDGET,
        self::USER_TEMPLATE,
    ];

    /** @var string */
    private $type;

    /**
     * @param string $type
     *
     * @throws InvalidPageBlockTypeException
     */
    public function __construct(string $type)
    {
        if (!in_array($type, self::POSSIBLE_TYPES, true)) {
            throw InvalidPageBlockTypeException::withType($type);
        }

        $this->type = $type;
    }

    public static function richText(): self
    {
        return new self(self::RICH_TEXT);
    }

    public static function block(): self
    {
        return new self(self::BLOCK);
    }

    public static function widget(): self
    {
        return new self(self::WIDGET);
    }

    public static function userTemplate(): self
    {
        return new self(self::USER_TEMPLATE);
    }

    public function __toString(): string
    {
        return $this->type;
    }

    public function jsonSerialize(): string
    {
        return (string) $this;
    }

    /**
     * @return self[]
     */
    public static function dropdownChoices(): array
    {
        $richText = self::richText();
        $block = self::block();
        $widget = self::widget();
        $userTemplate = self::userTemplate();

        return [
            $richText->getLabel() => $richText,
            $block->getLabel() => $block,
            $widget->getLabel() => $widget,
            $userTemplate->getLabel() => $userTemplate,
        ];
    }

    public function getLabel(): string
    {
        switch ($this->type) {
            case self::RICH_TEXT:
                return SpoonFilter::ucfirst(Language::lbl('Editor'));
            case self::BLOCK:
                return SpoonFilter::ucfirst(Language::lbl('Module'));
            case self::WIDGET:
                return SpoonFilter::ucfirst(Language::lbl('Widget'));
            case self::USER_TEMPLATE:
                return SpoonFilter::ucfirst(Language::lbl('UserTemplate'));
        }

        throw new RuntimeException('No label implemented for type: ' . $this->type);
    }
}
{'fraction_non_alphanumeric': 0.12433510638297872, 'fraction_numerical': 0.0, 'mean_word_length': 2.385596399099775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '1686618', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1276, 'n_words': 294}