lithium\test\filter\Profiler::apply PHP Метод

apply() публичный статический Метод

Takes an instance of an object (usually a Collection object) containing test instances. Allows for preparing tests before they are run.
public static apply ( object $report, array $tests, array $options = [] ) : object
$report object Instance of Report which is calling apply.
$tests array The test to apply this filter on
$options array Options for how this filter should be applied. Available options are: - `'method'` - `'run'` - `'checks'`
Результат object Returns the instance of `$tests`.
    public static function apply($report, $tests, array $options = array())
    {
        $defaults = array('method' => 'run', 'checks' => static::$_metrics);
        $options += $defaults;
        $m = $options['method'];
        $filter = function ($self, $params, $chain) use($report, $options) {
            $start = $results = array();
            $runCheck = function ($check) {
                switch (true) {
                    case is_object($check) || is_string($check):
                        return $check();
                        break;
                    case is_array($check):
                        $function = array_shift($check);
                        $result = !$check ? $check() : call_user_func_array($function, $check);
                        break;
                }
                return $result;
            };
            foreach ($options['checks'] as $name => $check) {
                $start[$name] = $runCheck($check['function']);
            }
            $methodResult = $chain->next($self, $params, $chain);
            foreach ($options['checks'] as $name => $check) {
                $results[$name] = $runCheck($check['function']) - $start[$name];
            }
            $report->collect(__CLASS__, array($self->subject() => $results, 'options' => $options + array('test' => get_class($self)), 'method' => $params['method']));
            return $methodResult;
        };
        $tests->invoke('applyFilter', array($m, $filter));
        return $tests;
    }