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.
Passed
Push — master ( ae15bb...f1056c )
by Odiseo
03:13
created

createNewWithArticleOrComment()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 2
dl 0
loc 23
rs 9.9
c 0
b 0
f 0
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 ($comment) {
0 ignored issues
show
introduced by
$comment is of type Odiseo\BlogBundle\Model\ArticleCommentInterface, thus it always evaluated to true.
Loading history...
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