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::createNew()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Odiseo\BlogBundle\Factory;
4
5
use Exception;
6
use Odiseo\BlogBundle\Doctrine\ORM\ArticleRepositoryInterface;
7
use Odiseo\BlogBundle\Model\ArticleCommentInterface;
8
use Odiseo\BlogBundle\Model\ArticleInterface;
9
use Sylius\Component\Resource\Repository\RepositoryInterface;
10
11
final class ArticleCommentFactory implements ArticleCommentFactoryInterface
12
{
13
    /** @var string */
14
    private $className;
15
16
    /** @var ArticleRepositoryInterface */
17
    private $articleRepository;
18
19
    /** @var RepositoryInterface */
20
    private $articleCommentRepository;
21
22
    public function __construct(
23
        string $className,
24
        ArticleRepositoryInterface $articleRepository,
25
        RepositoryInterface $articleCommentRepository
26
    )
27
    {
28
        $this->className = $className;
29
        $this->articleRepository = $articleRepository;
30
        $this->articleCommentRepository = $articleCommentRepository;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function createNew()
37
    {
38
        return new $this->className();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function createNewWithArticleOrComment(string $articleId, string $commentId = null): ArticleCommentInterface
45
    {
46
        /** @var ArticleCommentInterface $articleComment */
47
        $articleComment = $this->createNew();
48
49
        if ($commentId) {
50
            /** @var ArticleCommentInterface $comment */
51
            $comment = $this->articleCommentRepository->find($commentId);
52
            if (null !== $comment) {
53
                $articleComment->setParent($comment);
54
            }
55
        } else {
56
            /** @var ArticleInterface $article */
57
            $article = $this->articleRepository->find($articleId);
58
59
            if (!$article instanceof ArticleInterface) {
0 ignored issues
show
introduced by
$article is always a sub-type of Odiseo\BlogBundle\Model\ArticleInterface.
Loading history...
60
                throw new Exception();
61
            }
62
63
            $articleComment->setArticle($article);
64
        }
65
66
        return $articleComment;
67
    }
68
}
69