GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SetArticleAuthorListener::prePersist()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 4
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusBlogPlugin\Doctrine;
6
7
use Doctrine\ORM\Event\LifecycleEventArgs;
8
use Odiseo\SyliusBlogPlugin\Entity\ArticleInterface;
9
use Sylius\Component\Core\Model\AdminUserInterface;
10
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
11
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
12
13
final class SetArticleAuthorListener
14
{
15
    /** @var TokenStorageInterface */
16
    private $tokenStorage;
17
18
    public function __construct(
19
        TokenStorageInterface $tokenStorage
20
    ) {
21
        $this->tokenStorage = $tokenStorage;
22
    }
23
24
    /**
25
     * @param LifecycleEventArgs $args
26
     */
27
    public function prePersist(LifecycleEventArgs $args): void
28
    {
29
        $entity = $args->getEntity();
30
        $token = $this->tokenStorage->getToken();
31
32
        if ($entity instanceof ArticleInterface && $token instanceof TokenInterface) {
33
            $user = $token->getUser();
34
35
            if ($user instanceof AdminUserInterface) {
36
                $entity->setAuthor($user);
37
            }
38
        }
39
    }
40
}
41