Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
22.22% covered (danger)
22.22%
2 / 9
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AuditCreate
22.22% covered (danger)
22.22%
2 / 9
66.67% covered (warning)
66.67%
2 / 3
16.76
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEvent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getDescription
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2namespace Apie\Common\Other\Audit;
3
4use Apie\Common\Enums\AuditLogEvent;
5use Apie\Core\Context\ApieContext;
6use Apie\Core\Entities\EntityInterface;
7use Apie\Core\Translator\ApieTranslatorInterface;
8use Apie\Core\Translator\ValueObjects\AuditLogEventMessage;
9use Apie\Core\ValueObjects\NonEmptyString;
10
11class AuditCreate implements AuditEvent
12{
13    public function __construct(
14        private bool $withId
15    ) {
16    }
17
18    public function getEvent(): AuditLogEvent
19    {
20        return $this->withId ? AuditLogEvent::Replaced : AuditLogEvent::Created;
21    }
22
23    public function getDescription(
24        ApieTranslatorInterface $translator,
25        ApieContext $context,
26        string|EntityInterface|null $entity,
27    ): NonEmptyString {
28        assert(is_string($entity));
29        return NonEmptyString::fromNative(
30            $translator->getGeneralTranslation(
31                $context,
32                $this->withId ? AuditLogEventMessage::createResourceReplacedEvent($context) : AuditLogEventMessage::createResourceCreatedEvent($context)
33            )
34        );
35    }
36}