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\Web\Core\Component\Blog\Admin\Post; |
16
|
|
|
|
17
|
|
|
use Acme\App\Core\Component\Blog\Domain\Post\PostId; |
18
|
|
|
use Acme\App\Core\Port\TemplateEngine\TemplateViewModelInterface; |
19
|
|
|
use Acme\PhpExtension\ConstructableFromArrayInterface; |
20
|
|
|
use Acme\PhpExtension\ConstructableFromArrayTrait; |
21
|
|
|
use DateTimeInterface; |
22
|
|
|
|
23
|
|
View Code Duplication |
final class GetViewModel implements TemplateViewModelInterface, ConstructableFromArrayInterface |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
use ConstructableFromArrayTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var PostId |
29
|
|
|
*/ |
30
|
|
|
private $postId; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $postTitle; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var DateTimeInterface |
39
|
|
|
*/ |
40
|
|
|
private $postPublishedAt; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $postAuthorFullName; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private $postSummary; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private $postContent; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string[] |
59
|
|
|
*/ |
60
|
|
|
private $postTagList; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* The view model constructor depends on the most raw elements possible. |
64
|
|
|
*/ |
65
|
|
|
public function __construct( |
66
|
|
|
PostId $id, |
67
|
|
|
string $title, |
68
|
|
|
DateTimeInterface $publishedAt, |
69
|
|
|
string $authorFullName, |
70
|
|
|
string $summary, |
71
|
|
|
string $content, |
72
|
|
|
string ...$tagList |
73
|
|
|
) { |
74
|
|
|
$this->postId = $id; |
75
|
|
|
$this->postTitle = $title; |
76
|
|
|
$this->postPublishedAt = $publishedAt; |
77
|
|
|
$this->postAuthorFullName = $authorFullName; |
78
|
|
|
$this->postSummary = $summary; |
79
|
|
|
$this->postContent = $content; |
80
|
|
|
$this->postTagList = $tagList; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getPostId(): PostId |
84
|
|
|
{ |
85
|
|
|
return $this->postId; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getPostTitle(): string |
89
|
|
|
{ |
90
|
|
|
return $this->postTitle; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getPostPublishedAt(): DateTimeInterface |
94
|
|
|
{ |
95
|
|
|
return $this->postPublishedAt; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getPostAuthorFullName(): string |
99
|
|
|
{ |
100
|
|
|
return $this->postAuthorFullName; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getPostSummary(): string |
104
|
|
|
{ |
105
|
|
|
return $this->postSummary; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getPostContent(): string |
109
|
|
|
{ |
110
|
|
|
return $this->postContent; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string[] |
115
|
|
|
*/ |
116
|
|
|
public function getPostTagList(): array |
117
|
|
|
{ |
118
|
|
|
return $this->postTagList; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.