<commit_before><?php
namespace PSlim;

use PSlim\Service\AliasRegistry;
use PSlim\Service\InstanceStorage;
use PSlim\StandardException\NoInstance;
use PSlim\StandardException\NoMethodInClass;

/**
 * Invocation chain implementation
 *
 * @author lex
 *
 */
class InvocationChain extends ServiceLocatorUser {

    /**
     * Name of the instance to invoke method on
     *
     * @var string
     */
    private $instanceName = null;

    /**
     * Method to invoke
     *
     * @var string
     */
    private $method = null;

    /**
     * List of args to invoke method with
     *
     * @var array
     */
    private $args = null;

    /**
     * Link to instance storage object
     *
     * @var InstanceStorage
     */
    private $instanceStorage = null;

    /**
     * Link to alias registry object
     *
     * @var AliasRegistry
     */
    private $aliasRegistry = null;

    /**
     * Fixture object
     *
     * @var object
     */
    private $object = null;

    /**
     * Constructor
     *
     * @param string $instanceName
     * @param string $method
     * @param array $args
     */
    public function __construct($instanceName, $method, array $args) {
        $this->instanceName = $instanceName;
        $this->method = $method;
        $this->args = $args;

        $serviceLocator = $this->getServiceLocator();
        $this->instanceStorage = $serviceLocator->getInstanceStorage();
        $this->aliasRegistry = $serviceLocator->getAliasRegistry();
    }

    /**
     * Try to invoke a method
     *
     * @return mixed - result of invocation
     * @throws NoInstance - in case no instance is found and library objects
     *                      didn't help
     * @throws NoMethodInClass - in case no method is found anywhere
     */
    public function invoke() {
        if ($this->instanceExists()) {
            $result = $this->invokeOnFixture();
            if ($result) {
                return $this->getInvocationResult();
            }

            $result = $this->invokeOnSut();
            if ($result) {
                return $this->getInvocationResult();
            }
        }

        $result = $this->invokeOnLibrary();
        if ($result) {
            return $this->getInvocationResult();
        }

        $this->throwException();
    }

    /**
     * Check if instance exists
     *
     * @return boolean
     */
    private function instanceExists() {
        return
            $this->instanceStorage->hasInstance()
            && is_object($this->getObject())
        ;
    }

    /**
     * Get fixture object
     *
     * @return object
     */
    private function getObject() {
        if (null == $this->object) {
            $this->object = $this->instanceStorage->get($this->instanceName);
        }

        return $this->object;
    }

}<commit_msg>small changes<commit_after><?php
namespace PSlim;

use PSlim\Service\AliasRegistry;
use PSlim\Service\InstanceStorage;
use PSlim\StandardException\NoInstance;
use PSlim\StandardException\NoMethodInClass;

/**
 * Invocation chain implementation
 *
 * @author lex
 *
 */
class InvocationChain extends ServiceLocatorUser {

    /**
     * Name of the instance to invoke method on
     *
     * @var string
     */
    private $instanceName = null;

    /**
     * Method to invoke
     *
     * @var string
     */
    private $method = null;

    /**
     * List of args to invoke method with
     *
     * @var array
     */
    private $args = null;

    /**
     * Link to instance storage object
     *
     * @var InstanceStorage
     */
    private $instanceStorage = null;

    /**
     * Link to alias registry object
     *
     * @var AliasRegistry
     */
    private $aliasRegistry = null;

    /**
     * Fixture object
     *
     * @var object
     */
    private $object = null;

    /**
     * Constructor
     *
     * @param string $instanceName
     * @param string $method
     * @param array $args
     */
    public function __construct($instanceName, $method, array $args) {
        $this->instanceName = $instanceName;
        $this->method = $method;
        $this->args = $args;

        $serviceLocator = $this->getServiceLocator();
        $this->instanceStorage = $serviceLocator->getInstanceStorage();
        $this->aliasRegistry = $serviceLocator->getAliasRegistry();
    }

    /**
     * Try to invoke a method
     *
     * @return mixed - result of invocation
     * @throws NoInstance - in case no instance is found and library objects
     *                      didn't help
     * @throws NoMethodInClass - in case no method is found anywhere
     */
    public function invoke() {
        if ($this->instanceExists()) {
            $result = $this->invokeOnFixture();
            if ($result) {
                return $this->getInvocationResult();
            }

            $result = $this->invokeOnSut();
            if ($result) {
                return $this->getInvocationResult();
            }
        }

        $result = $this->invokeOnLibrary();
        if ($result) {
            return $this->getInvocationResult();
        }

        $this->throwException();
    }

    private function invokeOnFixture() {
        $object = $this->getObject();
        $method = $this->aliasRegistry->replaceMethodNameWithAlias(
            get_class($object), $this->method
        );

        if (!$this->isCallable($object, $method)) {
            return false;
        }

//         $this->invocationResult =
    }

    /**
     * Check if instance exists
     *
     * @return boolean
     */
    private function instanceExists() {
        return
            $this->instanceStorage->hasInstance()
            && is_object($this->getObject())
        ;
    }

    /**
     * Get fixture object
     *
     * @return object
     */
    private function getObject() {
        if (null == $this->object) {
            $this->object = $this->instanceStorage->get($this->instanceName);
        }

        return $this->object;
    }

}
{'fraction_non_alphanumeric': 0.12075283144570287, 'fraction_numerical': 0.0, 'mean_word_length': 1.8258823529411765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '4520560', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1622, 'n_words': 398}