<commit_before><?php

namespace li3_newrelic\extensions;

use lithium\action\Dispatcher;
use NewRelic\NewRelic as NewRelicAgent;

class NewRelic extends \lithium\core\StaticObject
{

    /**
     * @param  array $options
     * @return void
     */
    public static function init(array $options = array())
    {
        $options += array(
            'app_name' => defined('APP_NAME') ? APP_NAME : null,
            'license' => null,
            'filter' => true
        );

        if ($options['filter']) {
            Dispatcher::applyFilter('_callable', static::filter($options['filter']));
        }

        if ($options['app_name']) {
            if ($options['license']) {
                NewRelicAgent::getInstance()->setAppname($options['app_name'], $options['license']);
            } else {
                NewRelicAgent::getInstance()->setAppname($options['app_name']);
            }
        }
    }

    /**
     * @param  boolean|string $ransaction
     * @return \Closure
     */
    public static function filter($transaction = true)
    {
        return function($self, $params, $chain) use ($transaction) {
            $callable = $chain->next($self, $params, $chain);

            if ($transaction === 'url') {
                $transaction = $params['request']->url;
            } elseif ($transaction) {
                $name = get_class($callable);
                $class = substr($name, strrpos($name, '\\') + 1);
                $transaction = preg_replace('/Controller$/', '', $class) . '/' . $params['request']->params['action'];
            } else {
                return $callable;
            }

            NewRelicAgent::getInstance()->nameTransaction($transaction);

            return $callable;
        };
    }

}<commit_msg>- Remove extend, not needed - Use 5.4 array syntax - Improve php-doc<commit_after><?php

namespace li3_newrelic\extensions;

use \lithium\action\Dispatcher;
use \NewRelic\NewRelic as NewRelicAgent;

class NewRelic
{

    /**
     * Initialize the extension with provided conifugration
     *
     * @param  array $options
     * @return void
     */
    public static function init(array $options = [])
    {
        $options += [
            'app_name' => defined('APP_NAME') ? APP_NAME : null,
            'license' => null,
            'filter' => true
        ];

        if ($options['filter']) {
            Dispatcher::applyFilter('_callable', static::filter($options['filter']));
        }

        if ($options['app_name']) {
            if ($options['license']) {
                NewRelicAgent::setAppname($options['app_name'], $options['license']);
            } else {
                NewRelicAgent::setAppname($options['app_name']);
            }
        }
    }

    /**
     * Filter function for recording transaction name
     *
     * @param  boolean|string $transaction
     * @return \Closure
     */
    public static function filter($transaction = true)
    {
        return function($self, $params, $chain) use ($transaction) {
            $callable = $chain->next($self, $params, $chain);

            if ($transaction === 'url') {
                $transaction = $params['request']->url;
            } elseif ($transaction) {
                $name = get_class($callable);
                $class = substr($name, strrpos($name, '\\') + 1);
                $transaction = preg_replace('/Controller$/', '', $class) . '/' . $params['request']->params['action'];
            } else {
                return $callable;
            }

            NewRelicAgent::nameTransaction($transaction);

            return $callable;
        };
    }

}
{'fraction_non_alphanumeric': 0.15323025952512423, 'fraction_numerical': 0.0016565433462175593, 'mean_word_length': 1.9843492586490938, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '4975443', 'n_tokens_mistral': 1022, 'n_tokens_neox': 975, 'n_words': 196}