<commit_before><?php

namespace Pho\Framework;

use Webmozart\Assert\Assert;

class FieldHelper
{

    protected $value;
    protected $settings;

    /**
     * Constructor.
     * 
     * @param mixed $value The value to check.
     * @param array $settings Particle field settings.
     */
    public function __construct(/*mixed*/ $value, array $settings)
    {
        $this->value = $value;
        $this->settings = $settings;
    }

    /**
     * Applies directives to the value to return
     * 
     * @return mixed 
     */
    public function process() /*: mixed*/
    {
        if(!isset($this->settings["directives"]))
            return $this->value;
        $directives = $this->settings["directives"];
        $isDirectiveEnabled = function(string $param) use($directives): bool
        {
            return (isset($directives[$param]) && $directives[$param]);
        };
        if($isDirectiveEnabled("md5")) {
            return md5($this->value);
        }
        return $this->value;
    }

    /**
     * Checks if the field meets the requirements of the constraints in the 
     * particle's FIELDS constant.
     * 
     * @return void
     * 
     * @throws \InvalidArgumentException thrown when there argument does not meet the constraints.
     */
    public function probe(): void
    {
        if(!isset($this->settings["constraints"])) 
            return;
        $constraints = $this->settings["constraints"];
        foreach($constraints as $constraint=>$constraint_val) {
            if(is_null($constraint_val))
                continue;
            switch($constraint) {
                case "minLength":
                case "maxLength":
                case "greaterThan":
                case "lessThan":
                    Assert::$constraint($this->value, $constraint_val);
                    break;
                case "uuid":
                    Assert::$constraint($this->value);
                    break;
                case "regex":
                    Assert::$constraint($this->value, "/".addslashes($constraint_val)."/");
                    break;
             } 
        }
    }
}<commit_msg>code quality<commit_after><?php

/*
 * This file is part of the Pho package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Pho\Framework;

use Webmozart\Assert\Assert;

/**
 * Helps set up fields.
 * 
 * Used by AbstractEdge and Handlers\Set (for Nodes)
 * 
 * @author <NAME> <<EMAIL>>
 */
class FieldHelper
{

    protected $value;
    protected $settings;

    /**
     * Constructor.
     * 
     * @param mixed $value The value to check.
     * @param array $settings Particle field settings.
     */
    public function __construct(/*mixed*/ $value, array $settings)
    {
        $this->value = $value;
        $this->settings = $settings;
    }

    /**
     * Applies directives to the value to return
     * 
     * @return mixed 
     */
    public function process() /*: mixed*/
    {
        if(!isset($this->settings["directives"]))
            return $this->value;
        $directives = $this->settings["directives"];
        $isDirectiveEnabled = function(string $param) use($directives): bool
        {
            return (isset($directives[$param]) && $directives[$param]);
        };
        if($isDirectiveEnabled("md5")) {
            return md5($this->value);
        }
        return $this->value;
    }

    /**
     * Checks if the field meets the requirements of the constraints in the 
     * particle's FIELDS constant.
     * 
     * @return void
     * 
     * @throws \InvalidArgumentException thrown when there argument does not meet the constraints.
     */
    public function probe(): void
    {
        if(!isset($this->settings["constraints"])) 
            return;
        $constraints = $this->settings["constraints"];
        foreach($constraints as $constraint=>$constraint_val) {
            if(is_null($constraint_val))
                continue;
            switch($constraint) {
                case "minLength":
                case "maxLength":
                case "greaterThan":
                case "lessThan":
                    Assert::$constraint($this->value, $constraint_val);
                    break;
                case "uuid":
                    Assert::$constraint($this->value);
                    break;
                case "regex":
                    Assert::$constraint($this->value, "/".addslashes($constraint_val)."/");
                    break;
             } 
        }
    }
}
{'fraction_non_alphanumeric': 0.12662057044079517, 'fraction_numerical': 0.000864304235090752, 'mean_word_length': 1.8003629764065336, 'pattern_counts': {'":': 12, '<': 11, '<?xml version=': 0, '>': 35, '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': '6519616', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1190, 'n_words': 301}