<commit_before><?php

namespace MamuzBlog\Mapper\Db;

use MamuzBlog\Entity\Post;
use MamuzBlog\EventManager\Event;
use MamuzBlog\Feature\PostQueryInterface;
use MamuzBlog\Options\Constraint;
use MamuzBlog\Options\ConstraintInterface;

class PostQuery extends AbstractQuery implements PostQueryInterface
{
    const REPOSITORY = 'MamuzBlog\Entity\Post';

    /** @var ConstraintInterface */
    private $constraint;

    public function findPublishedPostById($id)
    {
        $results = $this->trigger(
            Event::PRE_FIND_PUBLISHED_POST,
            array('id' => $id),
            function ($result) {
                return ($result instanceof Post);
            }
        );
        if ($results->stopped()) {
            return $results->last();
        }

        $post = $this->getEntityManager()->find(self::REPOSITORY, $id);

        $this->trigger(Event::POST_FIND_PUBLISHED_POST, array('id' => $id, 'post' => $post));

        return $post;
    }

    public function findPublishedPosts()
    {
        $this->constraint = new Constraint;
        $this->constraint->add('published', 'p.published = :published', true);<commit_msg>Implement events<commit_after><?php

namespace MamuzBlog\Mapper\Db;

use MamuzBlog\EventManager\Event;
use MamuzBlog\Feature\PostQueryInterface;
use MamuzBlog\Options\Constraint;
use MamuzBlog\Options\ConstraintInterface;

class PostQuery extends AbstractQuery implements PostQueryInterface
{
    const REPOSITORY = 'MamuzBlog\Entity\Post';

    /** @var ConstraintInterface */
    private $constraint;

    public function findPublishedPostById($id)
    {
        $results = $this->trigger(Event::PRE_FIND_PUBLISHED_POST, array('id' => $id));
        if ($results->stopped()) {
            return $results->last();
        }

        $post = $this->getEntityManager()->find(self::REPOSITORY, $id);

        $this->trigger(Event::POST_FIND_PUBLISHED_POST, array('id' => $id, 'post' => $post));

        return $post;
    }

    public function findPublishedPosts()
    {
        $this->constraint = new Constraint;
        $this->constraint->add('published', 'p.published = :published', true);
{'fraction_non_alphanumeric': 0.1349206349206349, 'fraction_numerical': 0.0, 'mean_word_length': 3.2019607843137257, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '6799549', 'n_tokens_mistral': 655, 'n_tokens_neox': 613, 'n_words': 119}