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

CommentViewModel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A constructFromEntity() 0 8 1
A getId() 0 4 1
A getContent() 0 4 1
A getPublishedAt() 0 4 1
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\Comment;
16
17
use Acme\App\Core\Component\Blog\Domain\Post\Comment\Comment;
18
use DateTimeInterface;
19
20
final class CommentViewModel
21
{
22
    /**
23
     * @var string
24
     */
25
    private $id;
26
27
    /**
28
     * @var string
29
     */
30
    private $content;
31
32
    /**
33
     * @var DateTimeInterface
34
     */
35
    private $publishedAt;
36
37
    private function __construct(
38
        string $id,
39
        string $content,
40
        DateTimeInterface $publishedAt
41
    ) {
42
        $this->id = $id;
43
        $this->content = $content;
44
        $this->publishedAt = $publishedAt;
45
    }
46
47
    public static function constructFromEntity(Comment $comment): self
48
    {
49
        return new self(
50
            $comment->getId()->toScalar(),
51
            $comment->getContent(),
52
            $comment->getPublishedAt()
53
        );
54
    }
55
56
    public function getId(): string
57
    {
58
        return $this->id;
59
    }
60
61
    public function getContent(): string
62
    {
63
        return $this->content;
64
    }
65
66
    public function getPublishedAt(): DateTimeInterface
67
    {
68
        return $this->publishedAt;
69
    }
70
}
71