<commit_before><?php

namespace Gentry\Test;

use Exception;
use ReflectionFunction;
use ReflectionException;

class ProceduralFunction extends Feature
{
    private $fn;

    public function __construct(array $description, &$fn)
    {
        $this->fn = $fn;
        parent::__construct($description, '');
    }

    /**
     * Get a hash of actual function results.
     *
     * @param array $args Arguments to test with.
     * @return array A hash with value, thrown exception and output results.
     */
    public function actual(array $args)
    {
        $callargs = $args;
        unset($callargs[$this->target]);
        $callargs = array_values($callargs);
        $actual = ['thrown' => null, 'out' => '', 'result' => false];
        try {
            $function = new ReflectionFunction($this->fn);
        } catch (ReflectionException $e) {
            $actual['thrown'] = $e;
            return $actual;
        }
        ob_start();
        try {
            $actual['result'] = $function->invokeArgs($callargs);
        } catch (Exception $e) {
            $actual['thrown'] = $e;
        }
        $actual['out'] = \Gentry\cleanOutput(ob_get_clean());
        return $actual;
    }

    public function testedFeature()
    {
        return $this->fn;
    }
}
<commit_msg>simplify this so it can reuse more from Method testing<commit_after><?php

namespace Gentry\Test;

use Exception;
use Reflector;
use ReflectionFunction;
use ReflectionException;

class ProceduralFunction extends Method
{
    private $fn;

    public function __construct(array $description, $name, Reflector &$args)
    {
        $this->fn = $name;
        parent::__construct($description, '', null, $args);
    }

    /**
     * Get a hash of actual function results.
     *
     * @param array $args Arguments to test with.
     * @return array A hash with value, thrown exception and output results.
     */
    public function actual(array $args)
    {
        $actual = ['thrown' => null, 'out' => '', 'result' => false];
        try {
            $function = new ReflectionFunction($this->fn);
        } catch (ReflectionException $e) {
            $actual['thrown'] = $e;
            return $actual;
        }
        ob_start();
        try {
            $actual['result'] = $function->invokeArgs($this->args);
        } catch (Exception $e) {
            $actual['thrown'] = $e;
        }
        $actual['out'] = \Gentry\cleanOutput(ob_get_clean());
        return $actual;
    }

    public function testedFeature()
    {
        return $this->fn;
    }
}

{'fraction_non_alphanumeric': 0.13408913213448007, 'fraction_numerical': 0.0, 'mean_word_length': 2.226986128625473, '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': '3722580', 'n_tokens_mistral': 739, 'n_tokens_neox': 731, 'n_words': 194}