<commit_before><?php declare(strict_types=1);
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2017, <NAME>
 * @link      http://www.penguin33.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Phestival\Provider;

use Symfony\Component\Translation\TranslatorInterface;

/**
 * Time provider
 */
class TimeProvider implements ProviderInterface
{
    private const GENDER_FEMININE  = 'feminine';
    private const GENDER_MASCULINE = 'masculine';

    /**
     * @var \Symfony\Component\Translation\TranslatorInterface
     */
    private $translator;

    /**
     * @var \NumberFormatter
     */
    private $numberFormatter;

    /**
     * @param \Symfony\Component\Translation\TranslatorInterface $translator Translator
     */
    public function __construct(TranslatorInterface $translator)
    {
        $this->translator = $translator;

        $this->numberFormatter = new \NumberFormatter($translator->getLocale(), \NumberFormatter::SPELLOUT);
    }

    /**
     * {@inheritdoc}
     */
    public function get(): string
    {
        $hours   = $this->getHours();
        $minutes = $this->getMinutes();

        return $this->translator->trans('provider.time.text', [
            '%hours%'   => $hours,
            '%minutes%' => $minutes,
        ]);
    }

    /**
     * @return string
     */
    private function getHours(): string
    {
        $number = (int) (new \DateTimeImmutable())->format('H');

        return $this->translator->transChoice('provider.time.hours', $number, [
            '%number%' => $this->formatNumber($number),
        ]);
    }

    /**
     * @return string
     */
    private function getMinutes(): string
    {
        $number = (int) (new \DateTimeImmutable())->format('i');

        return 0 === $number
            ? $this->translator->trans('provider.time.exactly')
            : $this->translator->transChoice('provider.time.minutes', $number, [
                '%number%' => $this->formatNumber($number, self::GENDER_FEMININE),
            ]);
    }

    /**
     * @param int    $number Number
     * @param string $gender Gender
     *
     * @return string
     */
    private function formatNumber(int $number, string $gender = self::GENDER_MASCULINE): string
    {
        $this->numberFormatter->setTextAttribute(\NumberFormatter::DEFAULT_RULESET, '%spellout-cardinal-'.$gender);

        return $this->numberFormatter->format($number);
    }
}
<commit_msg>Change hours format in the time provider.<commit_after><?php declare(strict_types=1);
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2017, <NAME>
 * @link      http://www.penguin33.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Phestival\Provider;

use Symfony\Component\Translation\TranslatorInterface;

/**
 * Time provider
 */
class TimeProvider implements ProviderInterface
{
    private const GENDER_FEMININE  = 'feminine';
    private const GENDER_MASCULINE = 'masculine';

    /**
     * @var \Symfony\Component\Translation\TranslatorInterface
     */
    private $translator;

    /**
     * @var \NumberFormatter
     */
    private $numberFormatter;

    /**
     * @param \Symfony\Component\Translation\TranslatorInterface $translator Translator
     */
    public function __construct(TranslatorInterface $translator)
    {
        $this->translator = $translator;

        $this->numberFormatter = new \NumberFormatter($translator->getLocale(), \NumberFormatter::SPELLOUT);
    }

    /**
     * {@inheritdoc}
     */
    public function get(): string
    {
        $hours   = $this->getHours();
        $minutes = $this->getMinutes();

        return $this->translator->trans('provider.time.text', [
            '%hours%'   => $hours,
            '%minutes%' => $minutes,
        ]);
    }

    /**
     * @return string
     */
    private function getHours(): string
    {
        $number = (int) (new \DateTimeImmutable())->format('G');

        return $this->translator->transChoice('provider.time.hours', $number, [
            '%number%' => $this->formatNumber($number),
        ]);
    }

    /**
     * @return string
     */
    private function getMinutes(): string
    {
        $number = (int) (new \DateTimeImmutable())->format('i');

        return 0 === $number
            ? $this->translator->trans('provider.time.exactly')
            : $this->translator->transChoice('provider.time.minutes', $number, [
                '%number%' => $this->formatNumber($number, self::GENDER_FEMININE),
            ]);
    }

    /**
     * @param int    $number Number
     * @param string $gender Gender
     *
     * @return string
     */
    private function formatNumber(int $number, string $gender = self::GENDER_MASCULINE): string
    {
        $this->numberFormatter->setTextAttribute(\NumberFormatter::DEFAULT_RULESET, '%spellout-cardinal-'.$gender);

        return $this->numberFormatter->format($number);
    }
}

{'fraction_non_alphanumeric': 0.14793713163064834, 'fraction_numerical': 0.003143418467583497, 'mean_word_length': 2.590267983074753, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5369954', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1466, 'n_words': 290}