<commit_before><?php

namespace Marein\Nchan\Api\Model;

use Marein\Nchan\Exception\NchanException;

final class StatusInformation
{
    /**
     * @var array
     */
    private const REQUIRED_PLAIN_TEXT_KEYS = [
        'total published messages',
        'stored messages',
        'shared memory used',
        'channels',
        'subscribers',
        'redis pending commands',
        'redis connected servers',
        'total interprocess alerts received',
        'interprocess alerts in transit',
        'interprocess queued alerts',
        'total interprocess send delay',
        'total interprocess receive delay'
    ];

    /**
     * @var int
     */
    private $totalPublishedMessages;

    /**
     * @var int
     */
    private $storedMessages;

    /**
     * @var int
     */
    private $sharedMemoryUsed;

    /**
     * @var int
     */
    private $channels;

    /**
     * @var int
     */
    private $subscribers;

    /**
     * @var int
     */
    private $pendingRedisCommands;

    /**
     * @var int
     */
    private $connectedRedisServers;

    /**
     * @var int
     */
    private $totalReceivedInterprocessAlerts;

    /**
     * @var int
     */
    private $interprocessAlertsInTransit;

    /**
     * @var int
     */
    private $queuedInterprocessAlerts;

    /**
     * @var int
     */
    private $totalInterprocessSendDelay;

    /**
     * @var int
     */
    private $totalInterprocessReceiveDelay;

    /**
     * StatusInformation constructor.
     *
     * @param int $totalPublishedMessages
     * @param int $storedMessages
     * @param int $sharedMemoryUsed
     * @param int $channels
     * @param int $subscribers
     * @param int $pendingRedisCommands
     * @param int $connectedRedisServers
     * @param int $totalReceivedInterprocessAlerts
     * @param int $interprocessAlertsInTransit
     * @param int $queuedInterprocessAlerts
     * @param int $totalInterprocessSendDelay
     * @param int $totalInterprocessReceiveDelay
     */
    public function __construct(
        int $totalPublishedMessages,
        int $storedMessages,
        int $sharedMemoryUsed,
        int $channels,
        int $subscribers,
        int $pendingRedisCommands,
        int $connectedRedisServers,
        int $totalReceivedInterprocessAlerts,
        int $interprocessAlertsInTransit,
        int $queuedInterprocessAlerts,
        int $totalInterprocessSendDelay,
        int $totalInterprocessReceiveDelay
    ) {
        $this->totalPublishedMessages = $totalPublishedMessages;
        $this->storedMessages = $storedMessages;
        $this->sharedMemoryUsed = $sharedMemoryUsed;
        $this->channels = $channels;
        $this->subscribers = $subscribers;
        $this->pendingRedisCommands = $pendingRedisCommands;
        $this->connectedRedisServers = $connectedRedisServers;
        $this->totalReceivedInterprocessAlerts = $totalReceivedInterprocessAlerts;
        $this->interprocessAlertsInTransit = $interprocessAlertsInTransit;
        $this->queuedInterprocessAlerts = $queuedInterprocessAlerts;
        $this->totalInterprocessSendDelay = $totalInterprocessSendDelay;
        $this->totalInterprocessReceiveDelay = $totalInterprocessReceiveDelay;
    }

    /**
     * The plain text must look like this:
     *      total published messages: 3
     *      stored messages: 3
     *      shared memory used: 16K
     *      channels: 2
     *      subscribers: 2
     *      redis pending commands: 0
     *      redis connected servers: 2
     *      total interprocess alerts received: 0
     *      interprocess alerts in transit: 0
     *      interprocess queued alerts: 0
     *      total interprocess send delay: 0
     *      total interprocess receive delay: 0
     *
     * @param string $plainText
     *
     * @return StatusInformation
     * @throws NchanException
     */
    public static function fromPlainText(string $plainText): StatusInformation
    {
        $plainText = trim($plainText);
        $lines = explode("\n", $plainText);

        $response = [];
        foreach ($lines as $line) {
            list($key, $value) = explode(': ', $line);
            $response[$key] = $value;
        }

        // Check if required keys exists in $response.
        if (count(array_diff_key(array_flip(self::REQUIRED_PLAIN_TEXT_KEYS), $response)) !== 0) {
            throw new  NchanException(
                sprintf(
                    'Unable to parse status information: Keys "%s" are required. Keys "%s" exists.',
                    implode('", "', self::REQUIRED_PLAIN_TEXT_KEYS),
                    implode('", "', array_keys($response))
                )
            );
        }

        return new self(
            (int)$response['total published messages'],
            (int)$response['stored messages'],
            (int)$response['shared memory used'],
            (int)$response['channels'],
            (int)$response['subscribers'],
            (int)$response['redis pending commands'],
            (int)$response['redis connected servers'],
            (int)$response['total interprocess alerts received'],
            (int)$response['interprocess alerts in transit'],
            (int)$response['interprocess queued alerts'],
            (int)$response['total interprocess send delay'],
            (int)$response['total interprocess receive delay']
        );
    }

    /**
     * @return array
     */
    public static function requiredFromPlainTextKeys(): array
    {
        return self::$requiredFromPlainTextKeys;
    }

    /**
     * Number of messages published to all channels through this Nchan server.
     *
     * @return int
     */
    public function totalPublishedMessages(): int
    {
        return $this->totalPublishedMessages;
    }
<commit_msg>Remove unused method StatusInformation::requiredFromPlainTextKeys()<commit_after><?php

namespace Marein\Nchan\Api\Model;

use Marein\Nchan\Exception\NchanException;

final class StatusInformation
{
    /**
     * @var array
     */
    private const REQUIRED_PLAIN_TEXT_KEYS = [
        'total published messages',
        'stored messages',
        'shared memory used',
        'channels',
        'subscribers',
        'redis pending commands',
        'redis connected servers',
        'total interprocess alerts received',
        'interprocess alerts in transit',
        'interprocess queued alerts',
        'total interprocess send delay',
        'total interprocess receive delay'
    ];

    /**
     * @var int
     */
    private $totalPublishedMessages;

    /**
     * @var int
     */
    private $storedMessages;

    /**
     * @var int
     */
    private $sharedMemoryUsed;

    /**
     * @var int
     */
    private $channels;

    /**
     * @var int
     */
    private $subscribers;

    /**
     * @var int
     */
    private $pendingRedisCommands;

    /**
     * @var int
     */
    private $connectedRedisServers;

    /**
     * @var int
     */
    private $totalReceivedInterprocessAlerts;

    /**
     * @var int
     */
    private $interprocessAlertsInTransit;

    /**
     * @var int
     */
    private $queuedInterprocessAlerts;

    /**
     * @var int
     */
    private $totalInterprocessSendDelay;

    /**
     * @var int
     */
    private $totalInterprocessReceiveDelay;

    /**
     * StatusInformation constructor.
     *
     * @param int $totalPublishedMessages
     * @param int $storedMessages
     * @param int $sharedMemoryUsed
     * @param int $channels
     * @param int $subscribers
     * @param int $pendingRedisCommands
     * @param int $connectedRedisServers
     * @param int $totalReceivedInterprocessAlerts
     * @param int $interprocessAlertsInTransit
     * @param int $queuedInterprocessAlerts
     * @param int $totalInterprocessSendDelay
     * @param int $totalInterprocessReceiveDelay
     */
    public function __construct(
        int $totalPublishedMessages,
        int $storedMessages,
        int $sharedMemoryUsed,
        int $channels,
        int $subscribers,
        int $pendingRedisCommands,
        int $connectedRedisServers,
        int $totalReceivedInterprocessAlerts,
        int $interprocessAlertsInTransit,
        int $queuedInterprocessAlerts,
        int $totalInterprocessSendDelay,
        int $totalInterprocessReceiveDelay
    ) {
        $this->totalPublishedMessages = $totalPublishedMessages;
        $this->storedMessages = $storedMessages;
        $this->sharedMemoryUsed = $sharedMemoryUsed;
        $this->channels = $channels;
        $this->subscribers = $subscribers;
        $this->pendingRedisCommands = $pendingRedisCommands;
        $this->connectedRedisServers = $connectedRedisServers;
        $this->totalReceivedInterprocessAlerts = $totalReceivedInterprocessAlerts;
        $this->interprocessAlertsInTransit = $interprocessAlertsInTransit;
        $this->queuedInterprocessAlerts = $queuedInterprocessAlerts;
        $this->totalInterprocessSendDelay = $totalInterprocessSendDelay;
        $this->totalInterprocessReceiveDelay = $totalInterprocessReceiveDelay;
    }

    /**
     * The plain text must look like this:
     *      total published messages: 3
     *      stored messages: 3
     *      shared memory used: 16K
     *      channels: 2
     *      subscribers: 2
     *      redis pending commands: 0
     *      redis connected servers: 2
     *      total interprocess alerts received: 0
     *      interprocess alerts in transit: 0
     *      interprocess queued alerts: 0
     *      total interprocess send delay: 0
     *      total interprocess receive delay: 0
     *
     * @param string $plainText
     *
     * @return StatusInformation
     * @throws NchanException
     */
    public static function fromPlainText(string $plainText): StatusInformation
    {
        $plainText = trim($plainText);
        $lines = explode("\n", $plainText);

        $response = [];
        foreach ($lines as $line) {
            list($key, $value) = explode(': ', $line);
            $response[$key] = $value;
        }

        // Check if required keys exists in $response.
        if (count(array_diff_key(array_flip(self::REQUIRED_PLAIN_TEXT_KEYS), $response)) !== 0) {
            throw new  NchanException(
                sprintf(
                    'Unable to parse status information: Keys "%s" are required. Keys "%s" exists.',
                    implode('", "', self::REQUIRED_PLAIN_TEXT_KEYS),
                    implode('", "', array_keys($response))
                )
            );
        }

        return new self(
            (int)$response['total published messages'],
            (int)$response['stored messages'],
            (int)$response['shared memory used'],
            (int)$response['channels'],
            (int)$response['subscribers'],
            (int)$response['redis pending commands'],
            (int)$response['redis connected servers'],
            (int)$response['total interprocess alerts received'],
            (int)$response['interprocess alerts in transit'],
            (int)$response['interprocess queued alerts'],
            (int)$response['total interprocess send delay'],
            (int)$response['total interprocess receive delay']
        );
    }

    /**
     * Number of messages published to all channels through this Nchan server.
     *
     * @return int
     */
    public function totalPublishedMessages(): int
    {
        return $this->totalPublishedMessages;
    }

{'fraction_non_alphanumeric': 0.10310894365583907, 'fraction_numerical': 0.0024383871810502483, 'mean_word_length': 2.223126578725793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '5611054', 'n_tokens_mistral': 3171, 'n_tokens_neox': 3064, 'n_words': 724}