Passed
Push — develop ( 26eed0...9393b7 )
by BENARD
02:15
created

ArticleBuilder::setContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\ArticleBundle\Builder;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use ProjetNormandie\ArticleBundle\Entity\Article;
9
use ProjetNormandie\ArticleBundle\ValueObject\ArticleStatus;
0 ignored issues
show
Bug introduced by
The type ProjetNormandie\ArticleB...lueObject\ArticleStatus was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class ArticleBuilder
12
{
13
    private $author;
14
15
    /**
16
     * @var string[]
17
     */
18
    private array $titles = [];
19
20
    /**
21
     * @var string[]
22
     */
23
    private array $contents = [];
24
25
    private EntityManagerInterface $em;
26
27
    public function __construct(EntityManagerInterface $em)
28
    {
29
        $this->em = $em;
30
    }
31
32
    public function setAuthor($author): ArticleBuilder
33
    {
34
        $this->author = $author;
35
        return $this;
36
    }
37
38
    public function setTitle(string $title, string $lang): ArticleBuilder
39
    {
40
        $this->titles[$lang] = $title;
41
        return $this;
42
    }
43
44
    public function setContent(string $content, string $lang): ArticleBuilder
45
    {
46
        $this->contents[$lang] = $content;
47
        return $this;
48
    }
49
50
    public function send(): void
51
    {
52
        $article = new Article();
53
        $article->setAuthor($this->author);
54
        $article->setStatus(ArticleStatus::PUBLISHED);
55
        $article->setPublishedAt(new \DateTime());
56
57
        foreach ($this->titles as $lang => $value) {
58
            $article->setTitle($value, $lang);
59
        }
60
        foreach ($this->contents as $lang => $value) {
61
            $article->setContent($value, $lang);
62
        }
63
64
        $this->em->persist($article);
65
        $this->em->flush();
66
    }
67
}
68