<commit_before><?php

namespace Rainbow\Converter;

use Rainbow\ColorInterface;
use Rainbow\Hex;

final class RgbToHexConverter implements ConverterInterface
{
    /**
     * Returns the converted color
     * @return ColorInterface
     */
    public function convert()
    {
        return new Hex("#000000");
    }
}
<commit_msg>Test rgb to hex conversions<commit_after><?php

/**
 * This file is part of the Rainbow package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license MIT License
 */

namespace Rainbow\Converter;

use Rainbow\ColorInterface;
use Rainbow\Hex;
use Rainbow\Rgb;
use Rainbow\Unit\HexComponent;

final class RgbToHexConverter implements ConverterInterface
{
    /**
     * @var Rgb
     */
    private $color;

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

    /**
     * @param Rgb $color
     */
    function __construct(Rgb $color)
    {
        $this->color = $color;
        $this->hexValue = null;
    }

    /**
     * Returns the converted color
     * @return ColorInterface
     */
    public function convert()
    {
        if (!$this->isConverted()) {
            $this->updateHexValue();
        }

        return new Hex($this->hexValue);
    }

    private function isConverted()
    {
        return !is_null($this->hexValue);
    }

    private function updateHexValue()
    {
        $redHEx     = new HexComponent(dechex((string)$this->color->getRed()));
        $greenHEx   = new HexComponent(dechex((string)$this->color->getGreen()));
        $blueHEx    = new HexComponent(dechex((string)$this->color->getBlue()));

        $this->hexValue = sprintf(
            "#%s%s%s",
            $redHEx->getValue(),
            $greenHEx->getValue(),
            $blueHEx->getValue()
        );
    }
}

{'fraction_non_alphanumeric': 0.12621885157096424, 'fraction_numerical': 0.0032502708559046588, 'mean_word_length': 2.3581818181818184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '6530177', 'n_tokens_mistral': 556, 'n_tokens_neox': 532, 'n_words': 130}