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

CurrentUserProvider::provide()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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