Test Setup Failed
Push — graphql_api ( 4ff753 )
by Herberto
07:48 queued 01:35
created

PostViewModel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 6
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Presentation\Api\GraphQl\Node\Post;
16
17
use Acme\App\Core\Component\Blog\Domain\Post\Post;
18
use DateTimeInterface;
19
20
final class PostViewModel
21
{
22
    /**
23
     * @var string
24
     */
25
    private $id;
26
27
    /**
28
     * @var string
29
     */
30
    private $title;
31
32
    /**
33
     * @var string
34
     */
35
    private $slug;
36
37
    /**
38
     * @var string
39
     */
40
    private $summary;
41
42
    /**
43
     * @var string
44
     */
45
    private $content;
46
47
    /**
48
     * @var DateTimeInterface
49
     */
50
    private $publishedAt;
51
52
    private function __construct(
53
        string $id,
54
        string $title,
55
        string $slug,
56
        string $summary,
57
        string $content,
58
        DateTimeInterface $publishedAt
59
    ) {
60
        $this->id = $id;
61
        $this->title = $title;
62
        $this->slug = $slug;
63
        $this->summary = $summary;
64
        $this->content = $content;
65
        $this->publishedAt = $publishedAt;
66
    }
67
68
    public static function constructFromEntity(Post $post): self
69
    {
70
        return new self(
71
            $post->getId()->toScalar(),
72
            $post->getTitle(),
73
            $post->getSlug(),
74
            $post->getSummary(),
75
            $post->getContent(),
76
            $post->getPublishedAt()
77
        );
78
    }
79
80
    public function getId(): string
81
    {
82
        return $this->id;
83
    }
84
85
    public function getTitle(): string
86
    {
87
        return $this->title;
88
    }
89
90
    public function getSlug(): string
91
    {
92
        return $this->slug;
93
    }
94
95
    public function getSummary(): string
96
    {
97
        return $this->summary;
98
    }
99
100
    public function getContent(): string
101
    {
102
        return $this->content;
103
    }
104
105
    public function getPublishedAt(): DateTimeInterface
106
    {
107
        return $this->publishedAt;
108
    }
109
}
110