<commit_before><?php
/**
 * Go! OOP&AOP PHP framework
 *
 * @copyright     Copyright 2013, <NAME> <<EMAIL>>
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

namespace Go\Aop\Framework;

use Go\Aop\Intercept\MethodInvocation;
use Go\Aop\Intercept\MethodInterceptor;
use Go\Aop\Support\DynamicMethodMatcher;


/**
 * Dynamic method matcher combines a pointcut and interceptor.
 *
 * For each invocation interceptor asks the pointcut if it matches the invocation.
 * Matcher will receive reflection point, object instance and invocation arguments to make a decision
 *
 * @package go
 */
class DynamicMethodMatcherInterceptor implements MethodInterceptor
{

    /**
     * Instance of dynamic matcher
     *
     * @var DynamicMethodMatcher
     */
    private $matcher;

    /**
     * Instance of method interceptor to invoke
     *
     * @var MethodInterceptor
     */
    private $interceptor;

    /**
     * Dynamic matcher constructor
     *
     * @param DynamicMethodMatcher $matcher Instance of dynamic matcher
     * @param MethodInterceptor $interceptor Instance of method interceptor to invoke
     */
    public function __construct(DynamicMethodMatcher $matcher, MethodInterceptor $interceptor)
    {
        $this->matcher     = $matcher;
        $this->interceptor = $interceptor;
    }

    /**
     * Method invoker
     *
     * @param $invocation MethodInvocation the method invocation joinpoint
     * @return mixed the result of the call to {@see Joinpoint->proceed()}
     */
    final public function invoke(MethodInvocation $invocation)
    {
        if ($this->matcher->matches($invocation->getMethod(), $invocation->getThis(), $invocation->getArguments())) {
            return $this->interceptor->invoke($invocation);
        } else {
            return $invocation->proceed();
        }
    }
}
<commit_msg>Serialization/unserialization for dynamic method matcher #51<commit_after><?php
/**
 * Go! OOP&AOP PHP framework
 *
 * @copyright     Copyright 2013, <NAME> <<EMAIL>>
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

namespace Go\Aop\Framework;

use Go\Aop\Intercept\MethodInvocation;
use Go\Aop\Intercept\MethodInterceptor;
use Go\Aop\Support\DynamicMethodMatcher;


/**
 * Dynamic method matcher combines a pointcut and interceptor.
 *
 * For each invocation interceptor asks the pointcut if it matches the invocation.
 * Matcher will receive reflection point, object instance and invocation arguments to make a decision
 *
 * @package go
 */
class DynamicMethodMatcherInterceptor extends BaseInterceptor implements MethodInterceptor
{

    /**
     * Dynamic matcher constructor
     *
     * @param DynamicMethodMatcher $matcher Instance of dynamic matcher
     * @param MethodInterceptor $interceptor Instance of method interceptor to invoke
     */
    public function __construct(DynamicMethodMatcher $matcher, MethodInterceptor $interceptor)
    {
        $this->pointcut     = $matcher;
        $this->adviceMethod = $interceptor;
    }

    /**
     * Serializes an interceptor into string representation
     *
     * @return string the string representation of the object or null
     */
    public function serialize()
    {
        return serialize(array($this->pointcut, $this->adviceMethod));
    }

    /**
     * Unserialize an interceptor from the string
     *
     * @param string $serialized The string representation of the object.
     * @return void
     */
    public function unserialize($serialized)
    {
        list($this->pointcut, $this->adviceMethod) = unserialize(($serialized));
    }

    /**
     * Method invoker
     *
     * @param $invocation MethodInvocation the method invocation joinpoint
     * @return mixed the result of the call to {@see Joinpoint->proceed()}
     */
    final public function invoke(MethodInvocation $invocation)
    {
        if ($this->pointcut->matches($invocation->getMethod(), $invocation->getThis(), $invocation->getArguments())) {
            return $this->adviceMethod->invoke($invocation);
        } else {
            return $invocation->proceed();
        }
    }
}

{'fraction_non_alphanumeric': 0.10024038461538462, 'fraction_numerical': 0.002403846153846154, 'mean_word_length': 3.0555555555555554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7056219', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1109, 'n_words': 320}