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.

ArticleCommentFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 11
c 1
b 0
f 1
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A createNew() 0 3 1
A createNewWithArticleOrComment() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusBlogPlugin\Factory;
6
7
use Odiseo\BlogBundle\Factory\ArticleCommentFactoryInterface;
8
use Odiseo\BlogBundle\Model\ArticleCommentInterface;
9
use Sylius\Component\Core\Model\ShopUserInterface;
10
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
11
12
final class ArticleCommentFactory implements ArticleCommentFactoryInterface
13
{
14
    /** @var ArticleCommentFactoryInterface  */
15
    private $decoratedFactory;
16
17
    /** @var ShopUserInterface|object|string|null */
18
    private $shopUser;
19
20
    public function __construct(
21
        ArticleCommentFactoryInterface $decoratedFactory,
22
        TokenStorageInterface $tokenStorage
23
    ) {
24
        $this->decoratedFactory = $decoratedFactory;
25
26
        $token = $tokenStorage->getToken();
27
        $this->shopUser = $token !== null ? $token->getUser() : null;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function createNew(): object
34
    {
35
        return $this->decoratedFactory->createNew();
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function createNewWithArticleOrComment(string $articleId, string $commentId = null): ArticleCommentInterface
42
    {
43
        /** @var \Odiseo\SyliusBlogPlugin\Entity\ArticleCommentInterface $articleComment */
44
        $articleComment = $this->decoratedFactory->createNewWithArticleOrComment($articleId, $commentId);
45
46
        if ($this->shopUser instanceof ShopUserInterface) {
47
            $articleComment->setAuthor($this->shopUser);
48
        }
49
50
        return $articleComment;
51
    }
52
}
53