<commit_before><?php

namespace CodrPress\Controller;

use CodrPress\Helper\HttpCacheHelper;
use CodrPress\Helper\PaginationHelper;
use CodrPress\Model\Post;
use Silex\Application;
use Silex\ControllerProviderInterface;

class HomepageController implements ControllerProviderInterface
{

    public function connect(Application $app)
    {
        $router = $app['controllers_factory'];

        $router->get('/', function () use ($app) {
            $content = $app['twig']->render('posts.haml', $this->getTemplateData($app));

            return HttpCacheHelper::getResponse($app, $content, 200);
        })->bind('home');

        $router->get('/{page}/', function ($page) use ($app) {
            $content = $app['twig']->render('posts.haml', $this->getTemplateData($app, $page));

            return HttpCacheHelper::getResponse($app, $content, 200);
        })
            ->bind('home_page')
            ->assert('page', '\d+')
            ->convert('page', function ($page) { return (int)$page; });

        return $router;
    }

    private function getTemplateData(Application $app, $page = 1)
    {
        $posts = Post::posts();
        $pages = Post::pages();
        $tags = Post::tags();

        $config = $app['config'];
        $limit = $config->get('codrpress.layout.posts_per_page');
        $offset = $limit * ($page - 1);
        $posts = $posts->limit($limit)->skip($offset);
        $total = $posts->count();
        $templateData = [
            'config' => $config,
            'posts' => $posts->limit($limit)->skip($offset)->sort(['created_at' => -1]),
            'pages' => $pages->sort(['created_at' => -1]),
            'tags' => $tags
        ];

        if ($total > $limit) {
            $pagination = new PaginationHelper($app, 'home_page', [], $page, $limit);
            $templateData['pagination'] = $pagination->getPagination($total);
        }

        return $templateData;
    }
}<commit_msg>removed unnecessary line and added comment for more clarity<commit_after><?php

namespace CodrPress\Controller;

use CodrPress\Helper\HttpCacheHelper;
use CodrPress\Helper\PaginationHelper;
use CodrPress\Model\Post;
use Silex\Application;
use Silex\ControllerProviderInterface;

class HomepageController implements ControllerProviderInterface
{

    public function connect(Application $app)
    {
        $router = $app['controllers_factory'];

        $router->get('/', function () use ($app) {
            $content = $app['twig']->render('posts.haml', $this->getTemplateData($app));

            return HttpCacheHelper::getResponse($app, $content, 200);
        })->bind('home');

        $router->get('/{page}/', function ($page) use ($app) {
            $content = $app['twig']->render('posts.haml', $this->getTemplateData($app, $page));

            return HttpCacheHelper::getResponse($app, $content, 200);
        })
            ->bind('home_page')
            ->assert('page', '\d+')
            ->convert('page', function ($page) { return (int)$page; });

        return $router;
    }

    private function getTemplateData(Application $app, $page = 1)
    {
        $config = $app['config'];

        $posts = Post::posts();
        $pages = Post::pages();
        $tags = Post::tags();

        # pagination values
        $limit = $config->get('codrpress.layout.posts_per_page');
        $offset = $limit * ($page - 1);
        $total = $posts->count();

        $templateData = [
            'config' => $config,
            'posts' => $posts->limit($limit)->skip($offset)->sort(['created_at' => -1]),
            'pages' => $pages->sort(['created_at' => -1]),
            'tags' => $tags
        ];

        if ($total > $limit) {
            $pagination = new PaginationHelper($app, 'home_page', [], $page, $limit);
            $templateData['pagination'] = $pagination->getPagination($total);
        }

        return $templateData;
    }
}
{'fraction_non_alphanumeric': 0.17946084724005135, 'fraction_numerical': 0.005134788189987163, 'mean_word_length': 2.6445275958840035, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '3130599', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1118, 'n_words': 220}