<commit_before><?php
namespace Laranix\Support;

use Laranix\Support\Exception\LaranixSettingsException;
use Laranix\Support\IO\Str\Str;

abstract class Settings
{
    /**
     * Required properties
     *
     * @var array
     */
    protected $required = [];

    /**
     * Required types (if not set in $this->required)
     *
     * @var array
     */
    protected $requiredTypes = [];

    /**
     * Ignored properties
     * Useful if all are set to required but you want
     * to exclude some
     *
     * @var array
     */
    protected $ignored = [];

    /**
     * Required properties and types parsed in to one array
     *
     * @var array
     */
    protected $requiredParsed;

    /**
     * If all properties are required
     *
     * @var bool
     */
    protected $allRequired = false;

    /**
     * Settings constructor.
     *
     * @param array $values
     */
    public function __construct(array $values = [])
    {
        $this->assignPropertyValues($values);

        $this->setRequiredProperties($this->required);
    }

    /**
     * Assign values to properties
     *
     * @param array $values
     */
    protected function assignPropertyValues(array $values)
    {
        foreach ($values as $property => $value) {
            if (property_exists($this, $property)) {
                $this->{$property} = $value;
            }
        }
    }

    /**
     * Check the settings have all required settings with valid types
     *
     * @param   bool $refresh
     * @return  bool
     */
    public function hasRequiredSettings(bool $refresh = false)
    {
        $required = $this->getParsedRequiredProperties($refresh);

        if (!$this->allRequired && (empty($required) || $required === null)) {
            return true;
        }

        foreach ($required as $property => $allowed) {
            $this->validateProperty($property, $allowed);
        }

        return true;
    }

    /**
     * Validate the property against its allowed types
     *
     * @param string $property
     * @param array  $allowed
     * @throws \Laranix\Support\Exception\LaranixSettingsException
     */
    protected function validateProperty(string $property, array $allowed)
    {
        $types = array_flip($allowed);

        if (empty($types) || isset($types['null'])) {
            if ($this->{$property} !== null) {
                throw new LaranixSettingsException(sprintf("'%s' is required but not set in %s", $property, get_class($this)));
            }

            return;
        }<commit_msg>Remove null check Handled by normal validator now<commit_after><?php
namespace Laranix\Support;

use Laranix\Support\Exception\LaranixSettingsException;
use Laranix\Support\IO\Str\Str;

abstract class Settings
{
    /**
     * Required properties
     *
     * @var array
     */
    protected $required = [];

    /**
     * Required types (if not set in $this->required)
     *
     * @var array
     */
    protected $requiredTypes = [];

    /**
     * Ignored properties
     * Useful if all are set to required but you want
     * to exclude some
     *
     * @var array
     */
    protected $ignored = [];

    /**
     * Required properties and types parsed in to one array
     *
     * @var array
     */
    protected $requiredParsed;

    /**
     * If all properties are required
     *
     * @var bool
     */
    protected $allRequired = false;

    /**
     * Settings constructor.
     *
     * @param array $values
     */
    public function __construct(array $values = [])
    {
        $this->assignPropertyValues($values);

        $this->setRequiredProperties($this->required);
    }

    /**
     * Assign values to properties
     *
     * @param array $values
     */
    protected function assignPropertyValues(array $values)
    {
        foreach ($values as $property => $value) {
            if (property_exists($this, $property)) {
                $this->{$property} = $value;
            }
        }
    }

    /**
     * Check the settings have all required settings with valid types
     *
     * @param   bool $refresh
     * @return  bool
     */
    public function hasRequiredSettings(bool $refresh = false)
    {
        $required = $this->getParsedRequiredProperties($refresh);

        if (!$this->allRequired && (empty($required) || $required === null)) {
            return true;
        }

        foreach ($required as $property => $allowed) {
            $this->validateProperty($property, $allowed);
        }

        return true;
    }

    /**
     * Validate the property against its allowed types
     *
     * @param string $property
     * @param array  $allowed
     * @throws \Laranix\Support\Exception\LaranixSettingsException
     */
    protected function validateProperty(string $property, array $allowed)
    {
        $types = array_flip($allowed);
{'fraction_non_alphanumeric': 0.11860226104830421, 'fraction_numerical': 0.0, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '205945', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1311, 'n_words': 350}