<commit_before><?php

namespace CultuurNet\UDB3\Role\ReadModel\Detail;

use Broadway\Domain\DomainMessage;
use CultuurNet\UDB3\Role\Events\ConstraintCreated;
use CultuurNet\UDB3\Role\Events\ConstraintRemoved;
use CultuurNet\UDB3\Role\Events\ConstraintUpdated;
use CultuurNet\UDB3\Role\Events\RoleCreated;
use CultuurNet\UDB3\Role\Events\RoleDeleted;
use CultuurNet\UDB3\Role\Events\RoleRenamed;
use CultuurNet\UDB3\Role\ReadModel\RoleProjector;

class Projector extends RoleProjector
{
    /**
     * @param RoleCreated $roleCreated
     * @param DomainMessage $domainMessage
     */
    protected function applyRoleCreated(
        RoleCreated $roleCreated,
        DomainMessage $domainMessage
    ) {
        $this->saveNewDocument(
            $roleCreated->getUuid()->toNative(),
            function (\stdClass $json) use ($roleCreated, $domainMessage) {
                $json->{'uuid'} = $roleCreated->getUuid()->toNative();
                $json->name = $roleCreated->getName()->toNative();

                return $json;
            }
        );
    }

    /**
     * @param RoleRenamed $roleRenamed
     * @param DomainMessage $domainMessage
     */
    protected function applyRoleRenamed(
        RoleRenamed $roleRenamed,
        DomainMessage $domainMessage
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $roleRenamed->getUuid()->toNative()
        );

        $json = $document->getBody();
        $json->name = $roleRenamed->getName()->toNative();

        $this->repository->save($document->withBody($json));
    }

    /**
     * @param RoleDeleted $roleDeleted
     * @param DomainMessage $domainMessage
     */
    protected function applyRoleDeleted(
        RoleDeleted $roleDeleted,
        DomainMessage $domainMessage
    ) {
        $this->repository->remove($roleDeleted->getUuid());
    }

    /**
     * @param \CultuurNet\UDB3\Role\Events\ConstraintCreated $constraintCreated
     * @param \Broadway\Domain\DomainMessage $domainMessage
     */
    protected function applyConstraintCreated(
        ConstraintCreated $constraintCreated,
        DomainMessage $domainMessage
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $constraintCreated->getUuid()->toNative()
        );

        $json = $document->getBody();
        $json->constraint = $constraintCreated->getQuery()->toNative();

        $this->repository->save($document->withBody($json));
    }

    /**
     * @param \CultuurNet\UDB3\Role\Events\ConstraintUpdated $constraintUpdated
     * @param \Broadway\Domain\DomainMessage $domainMessage
     */
    protected function applyConstraintUpdated(
        ConstraintUpdated $constraintUpdated,
        DomainMessage $domainMessage
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $constraintUpdated->getUuid()->toNative()
        );

        $json = $document->getBody();
        $json->constraint = $constraintUpdated->getQuery()->toNative();

        $this->repository->save($document->withBody($json));
    }

    /**
     * @param \CultuurNet\UDB3\Role\Events\ConstraintRemoved $constraintRemoved
     * @param \Broadway\Domain\DomainMessage $domainMessage
     */
    protected function applyConstraintRemoved(
        ConstraintRemoved $constraintRemoved,
        DomainMessage $domainMessage
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $constraintRemoved->getUuid()->toNative()
        );

        $json = $document->getBody();
        unset($json->constraint);

        $this->repository->save($document->withBody($json));
    }
}
<commit_msg>III-1320: Remove unused DomainMessage params<commit_after><?php

namespace CultuurNet\UDB3\Role\ReadModel\Detail;

use CultuurNet\UDB3\Role\Events\ConstraintCreated;
use CultuurNet\UDB3\Role\Events\ConstraintRemoved;
use CultuurNet\UDB3\Role\Events\ConstraintUpdated;
use CultuurNet\UDB3\Role\Events\RoleCreated;
use CultuurNet\UDB3\Role\Events\RoleDeleted;
use CultuurNet\UDB3\Role\Events\RoleRenamed;
use CultuurNet\UDB3\Role\ReadModel\RoleProjector;

class Projector extends RoleProjector
{
    /**
     * @param RoleCreated $roleCreated
     */
    protected function applyRoleCreated(
        RoleCreated $roleCreated
    ) {
        $this->saveNewDocument(
            $roleCreated->getUuid()->toNative(),
            function (\stdClass $json) use ($roleCreated) {
                $json->{'uuid'} = $roleCreated->getUuid()->toNative();
                $json->name = $roleCreated->getName()->toNative();

                return $json;
            }
        );
    }

    /**
     * @param RoleRenamed $roleRenamed
     */
    protected function applyRoleRenamed(
        RoleRenamed $roleRenamed
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $roleRenamed->getUuid()->toNative()
        );

        $json = $document->getBody();
        $json->name = $roleRenamed->getName()->toNative();

        $this->repository->save($document->withBody($json));
    }

    /**
     * @param RoleDeleted $roleDeleted
     */
    protected function applyRoleDeleted(
        RoleDeleted $roleDeleted
    ) {
        $this->repository->remove($roleDeleted->getUuid());
    }

    /**
     * @param ConstraintCreated $constraintCreated
     */
    protected function applyConstraintCreated(
        ConstraintCreated $constraintCreated
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $constraintCreated->getUuid()->toNative()
        );

        $json = $document->getBody();
        $json->constraint = $constraintCreated->getQuery()->toNative();

        $this->repository->save($document->withBody($json));
    }

    /**
     * @param ConstraintUpdated $constraintUpdated
     */
    protected function applyConstraintUpdated(
        ConstraintUpdated $constraintUpdated
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $constraintUpdated->getUuid()->toNative()
        );

        $json = $document->getBody();
        $json->constraint = $constraintUpdated->getQuery()->toNative();

        $this->repository->save($document->withBody($json));
    }

    /**
     * @param ConstraintRemoved $constraintRemoved
     */
    protected function applyConstraintRemoved(
        ConstraintRemoved $constraintRemoved
    ) {
        $document = $this->loadDocumentFromRepositoryByUuid(
            $constraintRemoved->getUuid()->toNative()
        );

        $json = $document->getBody();
        unset($json->constraint);

        $this->repository->save($document->withBody($json));
    }
}

{'fraction_non_alphanumeric': 0.13055975794251135, 'fraction_numerical': 0.0034795763993948564, 'mean_word_length': 2.7626636311895276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 103, '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': '3091962', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1832, 'n_words': 265}