WordPress infinite post cycle

It should be more simple. Like this:

<?php
$next_post = get_previous_post();
if( empty( $next_post ) ) {
    $posts = get_posts( array( 'posts_per_page' => 1 ) );
    $next_post = $posts[0];
}
?>

<a href="https://wordpress.stackexchange.com/questions/244656/<?php echo get_permalink( $next_post->ID ); ?>">
    <span class="next"></span>
    <div class="featured-image" style="background-image: url('<?php echo wp_get_attachment_url( get_post_thumbnail_id( $next_post->ID ) ); ?>')"></div>
</a>
<div class="content">
    <?php
    echo apply_filters( 'the_content', get_post_field( 'post_content', $next_post->ID ) );
    ?>
</div>