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 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserAuthenticationContextBuilder
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 process
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2namespace Apie\LaravelApie\Wrappers\Security;
3
4use Apie\Common\Interfaces\UserDecorator;
5use Apie\Core\Context\ApieContext;
6use Apie\Core\ContextBuilders\ContextBuilderInterface;
7use Apie\Core\ContextConstants;
8
9class UserAuthenticationContextBuilder implements ContextBuilderInterface
10{
11    public function __construct(
12        private readonly LaravelUserDecoratorFactory $decoratorFactory
13    ) {
14    }
15    public function process(ApieContext $context): ApieContext
16    {
17        // @phpstan-ignore method.notFound
18        $user = auth()->user();
19        if ($user) {
20            $context = $context->registerInstance($user);
21
22            if ($user instanceof UserDecorator) {
23                $context = $context->withContext(ContextConstants::AUTHENTICATED_USER, $user->getEntity());
24            } else {
25                $context = $context->withContext(ContextConstants::AUTHENTICATED_USER, $this->decoratorFactory->create($user));
26            }
27        }
28
29        return $context;
30    }
31}