<commit_before><?php

declare(strict_types=1);

namespace MVLabs\EsCqrsWorkshop\Infrastructure\Projector;

use MVLabs\EsCqrsWorkshop\Domain\DomainEvent\OrderCompleted;

final class RecordPizzeriaOnOrderCompleted
{
    /**
     * @var \PDO
     */
    private $connection;

    public function __construct(\PDO $connection)
    {
        $this->connection = $connection;
    }

    public function __invoke(OrderCompleted $orderCompleted): void
    {
        $statement = $this->connection->prepare('');

        $statement->execute([
            'id' => (string)$orderCompleted->pizzeriaId(),
            'pizza' => $orderCompleted->pizzaTaste(),
            'customer' => $orderCompleted->customerName()
        ]);
    }
}<commit_msg>complete order projection<commit_after><?php

declare(strict_types=1);

namespace MVLabs\EsCqrsWorkshop\Infrastructure\Projector;

use MVLabs\EsCqrsWorkshop\Domain\DomainEvent\OrderCompleted;

final class RecordPizzeriaOnOrderCompleted
{
    /**
     * @var \PDO
     */
    private $connection;

    public function __construct(\PDO $connection)
    {
        $this->connection = $connection;
    }

    public function __invoke(OrderCompleted $orderCompleted): void
    {
        $statement = $this->connection->prepare(
            'UPDATE pizzerias SET pizzas = (' .
            '   SELECT to_jsonb(array_agg(ord)) FROM (' .
            '       SELECT ord FROM	(' .
            '           SELECT jsonb_array_elements(pizzas) AS ord FROM pizzerias) AS orders '.
            '           WHERE ord != jsonb_build_object(\'customer\', (:customer)::text, \'at\', (:at)::int, \'pizza\', (:pizza)::text) '.
            '       ) AS something '.
            '   )' .
            'WHERE id = :id'
        );

        $statement->execute([
            'id' => (string) $orderCompleted->pizzeriaId(),
            'pizza' => $orderCompleted->pizzaTaste(),
            'customer' => $orderCompleted->customerName(),
            'at' => $orderCompleted->orderCreatedAt()->format('U')
        ]);
    }
}
{'fraction_non_alphanumeric': 0.14088669950738916, 'fraction_numerical': 0.0009852216748768472, 'mean_word_length': 2.436548223350254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '936802', 'n_tokens_mistral': 613, 'n_tokens_neox': 591, 'n_words': 102}