<commit_before><?php

namespace Technodelight;

use Technodelight\SecondsToNone\Config;

class SecondsToNone
{
    private $config;

    public function __construct(Config $config = null)
    {
        $this->config = $config ?: new Config;
    }

    public function secondsToHuman($seconds)
    {
        $seconds = (int) $seconds;
        if ($seconds == 0) {
            return $this->config->number(0);
        }

        $human = [];
        foreach ($this->config as $stringRepresentation => $amount) {
            if ($seconds < 1 || $amount < 1) {
                break;
            }
            $value = floor($seconds / $amount);
            $seconds -= ($value * $amount);
            if ($value >= 1) {
                $human[] = sprintf($this->config->pattern(), $value, $stringRepresentation);
            }
        }
        return implode(' ', $human);
    }

    public function humanToSeconds($def)
    {
        if ($def == $this->config->number(0)) {
            return 0;
        }

        $buffer = '';
        $seconds = 0;
        $length = strlen($def);
        for ($pos = 0; $pos < $length; $pos++) {
            $char = substr($def, $pos, 1);
            $nextChar = substr($def, $pos + 1, 1);
            $buffer.= $char;

            list($number, $unit) = sscanf($buffer, $this->config->pattern());

            if ($this->isCurrentlyMatchingOnPattern($number, $unit, $nextChar)) {
                $seconds += $number * $this->config[$unit];
                $buffer = '';
            }
        }
        return $seconds;
    }

    /**
     * @param int|null $number
     * @param string $unit
     * @param string $nextChar
     * @return bool
     */
    private function isCurrentlyMatchingOnPattern($number, $unit, $nextChar)
    {
        return !is_null($number) && isset($this->config[$unit]) && (empty($nextChar) || $nextChar == ' ');
    }
}
<commit_msg>Fix suggestions by SC<commit_after><?php

namespace Technodelight;

use Technodelight\SecondsToNone\Config;

class SecondsToNone
{
    private $config;

    public function __construct(Config $config = null)
    {
        $this->config = $config ?: new Config;
    }

    public function secondsToHuman($seconds)
    {
        $seconds = (int) $seconds;
        if ($seconds == 0) {
            return $this->config->number(0);
        }

        $human = [];
        foreach ($this->config as $stringRepresentation => $amount) {
            if ($seconds < 1 || $amount < 1) {
                break;
            }
            $value = floor($seconds / $amount);
            $seconds -= ($value * $amount);
            if ($value >= 1) {
                $human[] = sprintf($this->config->pattern(), $value, $stringRepresentation);
            }
        }
        return implode(' ', $human);
    }

    public function humanToSeconds($def)
    {
        if ($def == $this->config->number(0)) {
            return 0;
        }

        return $this->collectSecondsFromText($def);
    }

    /**
     * @param string $def
     * @return int
     */
    private function collectSecondsFromText($def)
    {
        $buffer = '';
        $seconds = 0;
        $length = strlen($def);
        for ($pos = 0; $pos < $length; $pos++) {
            $char = substr($def, $pos, 1);
            $nextChar = substr($def, $pos + 1, 1);
            $buffer .= $char;

            list($number, $unit) = sscanf($buffer, $this->config->pattern());

            if ($this->isCurrentlyMatchingOnPattern($number, $unit, $nextChar)) {
                $seconds += $number * $this->config[$unit];
                $buffer = '';
            }
        }

        return $seconds;
    }

    /**
     * @param int|null $number
     * @param string $unit
     * @param string $nextChar
     * @return bool
     */
    private function isCurrentlyMatchingOnPattern($number, $unit, $nextChar)
    {
        return !is_null($number) && isset($this->config[$unit]) && (empty($nextChar) || $nextChar == ' ');
    }
}

{'fraction_non_alphanumeric': 0.15979899497487438, 'fraction_numerical': 0.006030150753768844, 'mean_word_length': 1.8294243070362473, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 34, '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': '1768284', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1143, 'n_words': 257}