protected function instantiateClass($class, array $args)
    {
        try {
            $reflectionMethod = new ReflectionMethod($class, '__construct');

            $ordered_arguments = Helper::parseParams(
                $reflectionMethod->getParameters(),
                $args
            );

            $reflectionClass = new ReflectionClass($class);

            return $reflectionClass->newInstanceArgs(
                (array)$ordered_arguments
            );
        } catch (Exception $exception) {
            throw new InvalidArgumentException(
                sprintf(
                    _('Failed to instantiate class "%1$s". Reason: %2$s'),
                    $class,
                    $exception->getMessage()
                )
            );
        }
    }