<commit_before><?php

namespace luya\helpers;

use Exception;
use ReflectionMethod;

class ObjectHelper
{
    public static function callMethodSanitizeArguments($object, $method, array $argumentsList = [])
    {
        $reflection = new ReflectionMethod($object, $method);
        
        $methodArgs = [];
        
        if ($reflection->getNumberOfRequiredParameters() > 0) {
            foreach ($reflection->getParameters() as $param) {
                if (!array_key_exists($param->name, $argumentsList)) {
                    throw new Exception("The provided argument '".$param->name."' does not exist in argument list for method '$method'.");
                }
                $methodArgs[] = $argumentsList[$param->name];
            }
        }
        
        return call_user_func_array(array($object, $method), $methodArgs);
    }
}<commit_msg>added phpdoc to object helper<commit_after><?php

namespace luya\helpers;

use Exception;
use ReflectionMethod;

/**
 * ObjectHelper to provied helper methods with class objects.
 *
 * @author nadar
 */
class ObjectHelper
{
    /**
     * Call a class method with arguments and verify the arguments if they are in the list of
     * method arguments or not.
     * 
     * @param object $object The class object where the method must be found.
     * @param string $method The class method to call inside the object
     * @param array $argumentsList A massiv assigned list of array items, where the key is bind
     * to the method argument and the value to be passed in the method on call.
     * @throws Exception Throws an exception if a argument coult not be found.
     * @return object
     */
    public static function callMethodSanitizeArguments($object, $method, array $argumentsList = [])
    {
        // get class refelction object
        $reflection = new ReflectionMethod($object, $method);
        // array where the sanitized arguemnts will be stored
        $methodArgs = [];
        // get all parematers of the $method
        if ($reflection->getNumberOfRequiredParameters() > 0) {
            foreach ($reflection->getParameters() as $param) {
                if (!array_key_exists($param->name, $argumentsList)) {
                    throw new Exception("The provided argument '".$param->name."' does not exist in argument list for method '$method'.");
                }
                $methodArgs[] = $argumentsList[$param->name];
            }
        }
        // call the object with method and arguments.
        return call_user_func_array([$object, $method], $methodArgs);
    }
}
{'fraction_non_alphanumeric': 0.10135922330097087, 'fraction_numerical': 0.0007766990291262136, 'mean_word_length': 2.519125683060109, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6060421', 'n_tokens_mistral': 667, 'n_tokens_neox': 654, 'n_words': 231}