Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
16.67% covered (danger)
16.67%
2 / 12
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AuditCreate
16.67% covered (danger)
16.67%
2 / 12
66.67% covered (warning)
66.67%
2 / 3
19.47
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 / 10
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\TranslationString;
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        $refl = new \ReflectionClass($entity);
30        return NonEmptyString::fromNative(
31            $translator->getGeneralTranslation(
32                $context,
33                new TranslationString(
34                    ($this->withId ? 'audit_log.replaced.' : 'audit_log.created.') . '.' . $refl->getShortName()
35                )
36            )
37        );
38    }
39}