<commit_before><?php
declare(strict_types=1);
namespace Nekudo\ShinyBlog\Domain;

use Nekudo\ShinyBlog\Exception\NotFoundException;

class ShowBlogDomain extends ContentDomain
{
    /** @var int $articleCount */
    protected $articleCount = 0;

    public function __construct(array $config)
    {
        parent::__construct($config);
    }

    /**
     * Fetches a list of articles ordered by date.
     *
     * @param int $page
     * @param string $category
     * @throws NotFoundException
     * @return array
     */
    public function getArticles(int $page = 0, string $category = '') : array
    {
        $this->loadArticleMeta('date');
        if (!empty($category)) {
            $this->filterArticlesByCategory($category);
        }
        krsort($this->articleMeta, SORT_NATURAL);
        $this->articleCount = count($this->articleMeta);

        // check if page number is valid:
        if ($this->pageIsValid($page) === false) {
            throw new NotFoundException('Invalid page number.');
        }<commit_msg>Throw 404 if category empty/not-found<commit_after><?php
declare(strict_types=1);
namespace Nekudo\ShinyBlog\Domain;

use Nekudo\ShinyBlog\Exception\NotFoundException;

class ShowBlogDomain extends ContentDomain
{
    /** @var int $articleCount */
    protected $articleCount = 0;

    public function __construct(array $config)
    {
        parent::__construct($config);
    }

    /**
     * Fetches a list of articles ordered by date.
     *
     * @param int $page
     * @param string $category
     * @throws NotFoundException
     * @return array
     */
    public function getArticles(int $page = 0, string $category = '') : array
    {
        $this->loadArticleMeta('date');
        if (!empty($category)) {
            $this->filterArticlesByCategory($category);
        }
        krsort($this->articleMeta, SORT_NATURAL);
        $this->articleCount = count($this->articleMeta);

        // throw 404 for empty categories:
        if ($this->articleCount === 0 && !empty($category)) {
            throw new NotFoundException('Category not found');
        }

        // check if page number is valid:
        if ($this->pageIsValid($page) === false) {
            throw new NotFoundException('Invalid page number.');
        }
{'fraction_non_alphanumeric': 0.12472551602986386, 'fraction_numerical': 0.005709266578831796, 'mean_word_length': 2.627388535031847, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '3925396', 'n_tokens_mistral': 656, 'n_tokens_neox': 628, 'n_words': 156}