<commit_before><?php
/*
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
namespace Welhott\Vatlidator;
use Welhott\Vatlidator\Cleaner\Country;
use Welhott\Vatlidator\Cleaner\ExtraCharacters;
use Welhott\Vatlidator\Cleaner\CleanerInterface;
use Welhott\Vatlidator\Cleaner\Trim;
use Welhott\Vatlidator\Cleaner\Uppercase;

/**
 * Interface VatProviderInterface
 * @package Welhott\Vatlidator
 */
abstract class VatProvider
{
    /**
     * The VAT number as a string because multiple providers have letters and also it's easier to work with the number.
     * @var string
     */
    protected $number;

    /**
     * @var string
     */
    protected $cleanNumber;

    /**
     * @var CleanerInterface[]
     */
    private $cleaners = [];

    /**
     * VatProvider constructor.
     * @param string $number
     * @param CleanerInterface[] $cleaners
     */
    public function __construct(string $number, array $cleaners = [])
    {
        $this->number = $number;
        $this->cleaners = [new Trim(), new Uppercase(), new ExtraCharacters(), new Country()];
        $this->cleanNumber = $this->clean($number);
    }

    /**
     * @param string $number
     * @return string
     */
    protected function clean(string $number) : string
    {
        $callback = function(string $number, CleanerInterface $transformer) {
            return $transformer->transform($number);
        };

        return array_reduce($this->cleaners, $callback, $number);
    }

    /**
     * @return bool
     */
    public abstract function validate() : bool;

    /**
     * @return string
     */
    public function getNumber() : string
    {
        return $this->number;
    }

    /**
     * Obtain the country code that represents this country.
     * @return string An ISO 3166-1 alpha-2 code that represents this country.
     */
    public abstract function getCountry() : string;

    /**
     * @return string
     */
    public abstract function getAbbreviation() : string;
}
<commit_msg>Created a helper method to obtain the check digit (or the possible check digit) of a number.<commit_after><?php
/*
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
namespace Welhott\Vatlidator;
use Welhott\Vatlidator\Cleaner\Country;
use Welhott\Vatlidator\Cleaner\ExtraCharacters;
use Welhott\Vatlidator\Cleaner\CleanerInterface;
use Welhott\Vatlidator\Cleaner\Trim;
use Welhott\Vatlidator\Cleaner\Uppercase;

/**
 * Interface VatProviderInterface
 * @package Welhott\Vatlidator
 */
abstract class VatProvider
{
    /**
     * The VAT number as a string because multiple providers have letters and also it's easier to work with the number.
     * @var string
     */
    protected $number;

    /**
     * @var string
     */
    protected $cleanNumber;

    /**
     * @var CleanerInterface[]
     */
    private $cleaners = [];

    /**
     * VatProvider constructor.
     * @param string $number
     * @param CleanerInterface[] $cleaners
     */
    public function __construct(string $number, array $cleaners = [])
    {
        $this->number = $number;
        $this->cleaners = [new Trim(), new Uppercase(), new ExtraCharacters(), new Country()];
        $this->cleanNumber = $this->clean($number);
    }

    /**
     * @param string $number
     * @return string
     */
    protected function clean(string $number) : string
    {
        $callback = function(string $number, CleanerInterface $transformer) {
            return $transformer->transform($number);
        };

        return array_reduce($this->cleaners, $callback, $number);
    }

    /**
     * @return bool
     */
    public abstract function validate() : bool;

    /**
     * Returns the check digit of a number. Use this when the check digit is only numbers.
     * @param int $length How many characters is the check digit.
     * @return int Returns the check digit of the number.
     */
    protected function getCheckDigit(int $length = 1) : int {
        return intval(mb_substr($this->cleanNumber, abs($length) * -1));
    }

    /**
     * Returns the check character of a number. Use this when the check digit is a letter or alphanumeric.
     * @param int $length How many characters is the check character.
     * @return string Returns the check digit of the number.
     */
    protected function getCheckChar(int $length = 1) : string {
        return mb_substr($this->cleanNumber, abs($length) * -1);
    }

    /**
     * @return string
     */
    public function getNumber() : string
    {
        return $this->number;
    }

    /**
     * Obtain the country code that represents this country.
     * @return string An ISO 3166-1 alpha-2 code that represents this country.
     */
    public abstract function getCountry() : string;

    /**
     * @return string
     */
    public abstract function getAbbreviation() : string;
}

{'fraction_non_alphanumeric': 0.09356978085351787, 'fraction_numerical': 0.002306805074971165, 'mean_word_length': 2.9685354691075516, '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': '2928880', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1839, 'n_words': 732}