<commit_before><?php

/*
 * This file is part of Methodology.
 * 
 * (c) <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view the LICENSE 
 * file that was distributed with this source code.
 */

namespace Methodology;

/**
 * Proxy object which manages access to Context inside closure.
 * 
 * @author <NAME> 
 */
class ContextProxy {
    /**
     * @var Context
     */
    protected $context;

    protected $result;

    protected $report;

    public function __construct(Context $context, Report &$report = null, Result &$result = null) {
        $this->context = $context;
        $this->report = $report;
        $this->result = $result;
    }

    /**
     * Resolves key in current scope.
     * 
     * @param string $key
     * @return mixed
     */
    public function __get($key) {
        return $this->context->resolve($key);    
    }

    /**
     * When is able to resolve $key returns its value, otherwise returns default. 
     * 
     * @param string    $key
     * @param callable  $code_block
     * @return mixed
     */
    public function _placeholder($key, $default) {
        try {
            return $this->__get($key);
        } catch(\Exception $e) {
            return $default;
        }
    }

    public function _stopDependencyChain() {
        $this->report(Report::DEPENDENCY_CHAIN_STOPPED);
    }

    public function _stopPropagationChain() {
        $this->report(Report::PROPAGATION_CHAIN_STOPPED);
    }

    /**
     * @throws CollectedNotification
     */
    public function _collect($value) {
        $this->report(Report::RESULT_COLLECTED);

        if(!is_null($this->result))
            $this->result->addPart($value);    
    }

    private function report($action) {
        if(!is_null($this->report))
            $this->report->occurred($action);
    }
}

<commit_msg>[feat] added magic __call to contextproxy<commit_after><?php

/*
 * This file is part of Methodology.
 * 
 * (c) <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information, please view the LICENSE 
 * file that was distributed with this source code.
 */

namespace Methodology;

/**
 * Proxy object which manages access to Context inside closure.
 * 
 * @author <NAME> 
 */
class ContextProxy {
    /**
     * @var Context
     */
    protected $context;

    protected $result;

    protected $report;

    public function __construct(Context $context, Report &$report = null, Result &$result = null) {
        $this->context = $context;
        $this->report = $report;
        $this->result = $result;
    }

    /**
     * Resolves key in current scope.
     * 
     * @param string $key
     * @return mixed
     */
    public function __get($key) {
        return $this->context->resolve($key);    
    }

    public function __call($name, $args) {
        return call_user_func_array($this->context->resolve($name), $args);
    }

    /**
     * When is able to resolve $key returns its value, otherwise returns default. 
     * 
     * @param string    $key
     * @param callable  $code_block
     * @return mixed
     */
    public function _placeholder($key, $default) {
        try {
            return $this->__get($key);
        } catch(\Exception $e) {
            return $default;
        }
    }

    public function _stopDependencyChain() {
        $this->report(Report::DEPENDENCY_CHAIN_STOPPED);
    }

    public function _stopPropagationChain() {
        $this->report(Report::PROPAGATION_CHAIN_STOPPED);
    }

    /**
     * @throws CollectedNotification
     */
    public function _collect($value) {
        $this->report(Report::RESULT_COLLECTED);

        if(!is_null($this->result))
            $this->result->addPart($value);    
    }

    private function report($action) {
        if(!is_null($this->report))
            $this->report->occurred($action);
    }
}


{'fraction_non_alphanumeric': 0.12836438923395446, 'fraction_numerical': 0.0, 'mean_word_length': 2.2754237288135593, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, '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': '5915291', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1101, 'n_words': 282}