Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SymfonyUserDecoratorIdentifier
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 createFrom
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 convert
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 getReferenceFor
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Apie\ApieBundle\Security;
4
5use Apie\Core\Identifiers\IdentifierInterface;
6use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException;
7use Apie\Core\ValueObjects\IsStringValueObject;
8use ReflectionClass;
9use Symfony\Component\Security\Core\User\UserInterface;
10
11/**
12 * @implements IdentifierInterface<SymfonyUserDecorator>
13 */
14final class SymfonyUserDecoratorIdentifier implements IdentifierInterface
15{
16    use IsStringValueObject;
17
18    /**
19     * @var class-string<UserInterface>
20     */
21    private string $userClass;
22
23    private string $userId;
24
25    public static function createFrom(UserInterface $user): self
26    {
27        return new self(get_class($user) . '@' . $user->getUserIdentifier());
28    }
29
30    protected function convert(string $input): string
31    {
32        $split = explode('@', $input, 2);
33        if (!class_exists($split[0])) {
34            throw new InvalidStringForValueObjectException($input, $this);
35        }
36        $this->userClass = $split[0];
37        $this->userId = $split[1];
38        return $this->userClass . '@' . $this->userId;
39    }
40
41    public static function getReferenceFor(): ReflectionClass
42    {
43        return new ReflectionClass(SymfonyUserDecorator::class);
44    }
45}