<commit_before><?php
/**
 * Bright Nucleus Options Store.
 *
 * Abstract options store that allows for exchangeable persistence mechanisms.
 *
 * @package   BrightNucleus\OptionsStore
 * @author    <NAME> <<EMAIL>>
 * @license   MIT
 * @link      https://www.brightnucleus.com/
 * @copyright 2017 <NAME>, Bright Nucleus
 */

namespace BrightNucleus\OptionsStore\OptionRepository;

use BrightNucleus\OptionsStore\Exception\UnknownOptionKey;

/**
 * Class WordPressOptionRepository.
 *
 * WordPress implementation for the OptionRepository, using WPDB as a backend.
 *
 * @since   0.1.0
 *
 * @package BrightNucleus\OptionsStore\OptionRepository
 * @author  <NAME> <<EMAIL>>
 */
final class WordPressOptionRepository extends AbstractOptionRepository implements Prefixable
{

    /**
     * Prefix to add to all option keys.
     *
     * @since 0.1.0
     *
     * @var string
     */
    private $prefix;

    /**
     * Instantiate a WordPressOptionRepository object.
     *
     * @since 0.1.0
     *
     * @param string $prefix  Optional. Prefix to add to all option keys. Defaults to an empty string (=> no prefix).
     * @param array  $options Optional. Array of Option instances that define available options and defaults.
     */
    public function __construct(string $prefix = '', array $options = [])
    {
        $this->prefix = $prefix;
        parent::__construct($options);
    }

    /**
     * Read a single option from the persistence mechanism.
     *
     * @since 0.1.0
     *
     * @param string $key      Key of the option to read.
     * @param mixed  $fallback Optional. Fallback value to use if the option was not found.
     *
     * @return mixed Value that was read.
     * @throws UnknownOptionKey If the value could not be retrieved.
     */
    protected function readOption(string $key, $fallback = null)
    {
        $value = get_option($this->prefix . $key, $fallback ?: false);
        if (false === $value) {
            throw UnknownOptionKey::fromKey($key);
        }

        return $value;
    }

    /**
     * Write a single option to the persistence mechanism.
     *
     * @since 0.1.0
     *
     * @param string $key   Key of the option to write.
     * @param mixed  $value Value to write.
     *
     * @return bool Whether the write operation was successful.
     */
    protected function writeOption(string $key, $value): bool
    {
        return update_option($this->prefix . $key, $value);
    }
}<commit_msg>Fix bug in `WordPressOptionRepository::writeOption()` method. Props @gmazzap.<commit_after><?php
/**
 * Bright Nucleus Options Store.
 *
 * Abstract options store that allows for exchangeable persistence mechanisms.
 *
 * @package   BrightNucleus\OptionsStore
 * @author    <NAME> <<EMAIL>>
 * @license   MIT
 * @link      https://www.brightnucleus.com/
 * @copyright 2017 <NAME>, Bright Nucleus
 */

namespace BrightNucleus\OptionsStore\OptionRepository;

use BrightNucleus\OptionsStore\Exception\UnknownOptionKey;

/**
 * Class WordPressOptionRepository.
 *
 * WordPress implementation for the OptionRepository, using WPDB as a backend.
 *
 * @since   0.1.0
 *
 * @package BrightNucleus\OptionsStore\OptionRepository
 * @author  <NAME> <<EMAIL>>
 */
final class WordPressOptionRepository extends AbstractOptionRepository implements Prefixable
{

    /**
     * Prefix to add to all option keys.
     *
     * @since 0.1.0
     *
     * @var string
     */
    private $prefix;

    /**
     * Instantiate a WordPressOptionRepository object.
     *
     * @since 0.1.0
     *
     * @param string $prefix  Optional. Prefix to add to all option keys. Defaults to an empty string (=> no prefix).
     * @param array  $options Optional. Array of Option instances that define available options and defaults.
     */
    public function __construct(string $prefix = '', array $options = [])
    {
        $this->prefix = $prefix;
        parent::__construct($options);
    }

    /**
     * Read a single option from the persistence mechanism.
     *
     * @since 0.1.0
     *
     * @param string $key      Key of the option to read.
     * @param mixed  $fallback Optional. Fallback value to use if the option was not found.
     *
     * @return mixed Value that was read.
     * @throws UnknownOptionKey If the value could not be retrieved.
     */
    protected function readOption(string $key, $fallback = null)
    {
        $value = get_option($this->prefix . $key, $fallback ?: false);
        if (false === $value) {
            throw UnknownOptionKey::fromKey($key);
        }

        return $value;
    }

    /**
     * Write a single option to the persistence mechanism.
     *
     * @since 0.1.0
     *
     * @param string $key   Key of the option to write.
     * @param mixed  $value Value to write.
     *
     * @return bool Whether the write operation was successful.
     */
    protected function writeOption(string $key, $value): bool
    {
        return $value === get_option($this->prefix . $key)
               || update_option($this->prefix . $key, $value);
    }
}
{'fraction_non_alphanumeric': 0.10711462450592886, 'fraction_numerical': 0.007509881422924901, 'mean_word_length': 2.519471488178025, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 26, 'https://': 2, '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': '4817605', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1414, 'n_words': 463}