<commit_before><?php
/**
 * Sikker is a PHP 7.0+ Security package that contains security related implementations.
 *
 * @package    NorseBlue\Sikker
 * @version    0.1
 * @author     NorseBlue
 * @license    MIT License
 * @copyright  2016 NorseBlue
 * @link       https://github.com/NorseBlue/Sikker
 */
declare(strict_types = 1);

namespace NorseBlue\Sikker\Hash;

use InvalidArgumentException;
use NorseBlue\Sikker\FileNotFoundException;
use RuntimeException;

/**
 * Class Hasher
 *
 * @package NorseBlue\Sikker\Hash
 * @uses Algorithm
 * @since 0.1
 */
class Hasher
{
    /**
     * @var string The hashing algorithm to use. Defaults ot SHA256.
     */
    protected $algorithm;

    /**
     * Hasher constructor.
     *
     * @param string|null $algorithm The selected algorithm or null to use the default.
     * @since 0.1
     */
    public function __construct(string $algorithm = null)
    {
        $this->setAlgorithm($algorithm);
    }

    /**
     * Gets the Hasher algorithm.
     *
     * @return string Returns the Hasher selected algorithm.
     * @since 0.1
     */
    public function getAlgorithm() : string
    {
        return $this->algorithm;
    }

    /**
     * Sets the Hasher algorithm.
     *
     * @param string|null $algorithm The algorithm to select for the Hasher. If null is given, the default algorithm will be used.
     * @throws AlgorithmNotAvailableException When the given algorithm is not available to be used.
     * @since 0.1
     */
    public function setAlgorithm(string $algorithm = null)
    {
        $algorithm = $algorithm ?? Algorithm::SHA256;
        if (!Algorithm::isAvailable($algorithm)) {
            throw new AlgorithmNotAvailableException($algorithm,
                "The given algorithm is not available in the current platform stack.");
        }
    }

    /**
     * Generates a hash value from the given payload using the Hasher selected algorithm.
     *<commit_msg>Fixed algorithm assignment<commit_after><?php
/**
 * Sikker is a PHP 7.0+ Security package that contains security related implementations.
 *
 * @package    NorseBlue\Sikker
 * @version    0.1
 * @author     NorseBlue
 * @license    MIT License
 * @copyright  2016 NorseBlue
 * @link       https://github.com/NorseBlue/Sikker
 */
declare(strict_types = 1);

namespace NorseBlue\Sikker\Hash;

use InvalidArgumentException;
use NorseBlue\Sikker\FileNotFoundException;
use RuntimeException;

/**
 * Class Hasher
 *
 * @package NorseBlue\Sikker\Hash
 * @uses Algorithm
 * @since 0.1
 */
class Hasher
{
    /**
     * @var string The hashing algorithm to use. Defaults ot SHA256.
     */
    protected $algorithm;

    /**
     * Hasher constructor.
     *
     * @param string|null $algorithm The selected algorithm or null to use the default.
     * @since 0.1
     */
    public function __construct(string $algorithm = null)
    {
        $this->setAlgorithm($algorithm);
    }

    /**
     * Gets the Hasher algorithm.
     *
     * @return string Returns the Hasher selected algorithm.
     * @since 0.1
     */
    public function getAlgorithm() : string
    {
        return $this->algorithm;
    }

    /**
     * Sets the Hasher algorithm.
     *
     * @param string|null $algorithm The algorithm to select for the Hasher. If null is given, the default algorithm will be used.
     * @throws AlgorithmNotAvailableException When the given algorithm is not available to be used.
     * @since 0.1
     */
    public function setAlgorithm(string $algorithm = null)
    {
        $algorithm = $algorithm ?? Algorithm::SHA256;
        if (!Algorithm::isAvailable($algorithm)) {
            throw new AlgorithmNotAvailableException($algorithm,
                "The given algorithm is not available in the current platform stack.");
        }
        $this->algorithm = $algorithm;
    }

    /**
     * Generates a hash value from the given payload using the Hasher selected algorithm.
     *
{'fraction_non_alphanumeric': 0.09608540925266904, 'fraction_numerical': 0.011692933401118455, 'mean_word_length': 2.5482416591523895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '309683', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1070, 'n_words': 354}