Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
20.00% covered (danger)
20.00%
2 / 10
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AuditRead
20.00% covered (danger)
20.00%
2 / 10
66.67% covered (warning)
66.67%
2 / 3
12.19
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
1
 getDescription
0.00% covered (danger)
0.00%
0 / 8
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 AuditRead implements AuditEvent
12{
13    public function __construct(
14        private bool $fromList = false
15    ) {
16    }
17
18    public function getEvent(): AuditLogEvent
19    {
20        return AuditLogEvent::Read;
21    }
22
23    public function getDescription(
24        ApieTranslatorInterface $translator,
25        ApieContext $context,
26        string|EntityInterface|null $entity,
27    ): NonEmptyString {
28        assert($entity !== null);
29        $refl = new \ReflectionClass($entity);
30        return NonEmptyString::fromNative(
31            $translator->getGeneralTranslation(
32                $context,
33                new TranslationString(($this->fromList ? 'audit_log.read_list.' : 'audit_log.read.') . $refl->getShortName())
34            )
35        );
36    }
37}