src/Aspect/AbstractContractAspect.php
protected function ensureContracts(
        MethodInvocation $invocation,
        array $contracts,
        $instance,
        string $scope,
        array $args
    ): void {
        static $invoker = null;
        if (!$invoker) {
            $invoker = function () {
                $args = \func_get_arg(0);
                \extract($args, EXTR_OVERWRITE);

                return eval('return ' . \func_get_arg(1) . '; ?>');
            };
        }

        $instance     = \is_object($instance) ? $instance : null;
        $boundInvoker = $invoker->bindTo($instance, $scope);

        foreach ($contracts as $contract) {
            $contractExpression = $contract->value;
            try {
                $invocationResult = $boundInvoker->__invoke($args, $contractExpression);

                if ($invocationResult === false) {
                    throw new ContractViolation($invocation, $contractExpression);
                }

                // we accept as a result only true or null
                // null may be a result of assertions from beberlei/assert which passed
                if ($invocationResult !== null && $invocationResult !== true) {
                    $errorMessage = 'Invalid return value received from the assertion body,'
                        . ' only boolean or void can be returned';
                    throw new DomainException($errorMessage);
                }
            } catch (\Error $internalError) {
                // PHP-7 friendly interceptor for fatal errors
                throw new ContractViolation($invocation, $contractExpression, $internalError);
            } catch (\Exception $internalException) {
                throw new ContractViolation($invocation, $contractExpression, $internalException);
            }
        }
    }
protected function ensureContracts(
        MethodInvocation $invocation,
        array $contracts,
        $instance,
        string $scope,
        array $args
    ): void {
        static $invoker = null;
        if (!$invoker) {
            $invoker = function () {
                $args = \func_get_arg(0);
                \extract($args, EXTR_OVERWRITE);

                return eval('return ' . \func_get_arg(1) . '; ?>');
            };
        }

        $instance     = \is_object($instance) ? $instance : null;
        $boundInvoker = $invoker->bindTo($instance, $scope);

        foreach ($contracts as $contract) {
            $contractExpression = $contract->value;
            try {
                $invocationResult = $boundInvoker->__invoke($args, $contractExpression);

                if ($invocationResult === false) {
                    throw new ContractViolation($invocation, $contractExpression);
                }

                // we accept as a result only true or null
                // null may be a result of assertions from beberlei/assert which passed
                if ($invocationResult !== null && $invocationResult !== true) {
                    $errorMessage = 'Invalid return value received from the assertion body,'
                        . ' only boolean or void can be returned';
                    throw new DomainException($errorMessage);
                }
            } catch (\Error $internalError) {
                // PHP-7 friendly interceptor for fatal errors
                throw new ContractViolation($invocation, $contractExpression, $internalError);
            } catch (\Exception $internalException) {
                throw new ContractViolation($invocation, $contractExpression, $internalException);
            }
        }
    }
protected function ensureContracts ( MethodInvocation $ invocation , array $ contracts , $ instance , string $ scope , array $ args ) : void { static $ invoker = null ; if ( ! $ invoker ) { $ invoker = function ( ) { $ args = \ func_get_arg ( 0 ) ; \ extract ( $ args , EXTR_OVERWRITE ) ; return eval ( 'return ' . \ func_get_arg ( 1 ) . '; ?>' ) ; } ; } $ instance = \ is_object ( $ instance ) ? $ instance : null ; $ boundInvoker = $ invoker -> bindTo ( $ instance , $ scope ) ; foreach ( $ contracts as $ contract ) { $ contractExpression = $ contract -> value ; try { $ invocationResult = $ boundInvoker -> __invoke ( $ args , $ contractExpression ) ; if ( $ invocationResult === false ) { throw new ContractViolation ( $ invocation , $ contractExpression ) ; } // we accept as a result only true or null // null may be a result of assertions from beberlei/assert which passed if ( $ invocationResult !== null && $ invocationResult !== true ) { $ errorMessage = 'Invalid return value received from the assertion body,' . ' only boolean or void can be returned' ; throw new DomainException ( $ errorMessage ) ; } } catch ( \ Error $ internalError ) { // PHP-7 friendly interceptor for fatal errors throw new ContractViolation ( $ invocation , $ contractExpression , $ internalError ) ; } catch ( \ Exception $ internalException ) { throw new ContractViolation ( $ invocation , $ contractExpression , $ internalException ) ; } } }
Performs verification of contracts for given invocation

@param MethodInvocation $invocation Current invocation
@param array|Annotation[] $contracts Contract annotation
@param object|string $instance Invocation instance or string for static class
@param string $scope Scope of method
@param array $args List of arguments for the method

@throws DomainException
@throws ContractViolation
Performs verification of contracts for given invocation