Completed
Pull Request — master (#229)
by
unknown
02:44
created

CurrentUserProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A provide() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Provider;
6
7
use Sylius\Component\Core\Model\ShopUserInterface;
8
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
9
use Webmozart\Assert\Assert;
10
11
final class CurrentUserProvider implements CurrentUserProviderInterface
12
{
13
    /**
14
     * @var TokenStorage
15
     */
16
    private $tokenStorage;
17
18
    public function __construct(TokenStorage $tokenStorage)
19
    {
20
        $this->tokenStorage = $tokenStorage;
21
    }
22
23
    /**
24
     * @return ShopUserInterface
25
     */
26
    public function provide(): ShopUserInterface
27
    {
28
        /** @var ShopUserInterface $user */
29
        $user = $this->tokenStorage->getToken()->getUser();
30
31
        Assert::isInstanceOf($user, ShopUserInterface::class);
32
33
        return $user;
34
    }
35
}
36