@@ -68,8 +68,6 @@ private function loadTags(ObjectManager $manager): void
68
68
69
69
private function loadPosts (ObjectManager $ manager ): void
70
70
{
71
- /** @var User $author */
72
- /** @var array<Tag> $tags */
73
71
foreach ($ this ->getPostData () as [$ title , $ slug , $ summary , $ content , $ publishedAt , $ author , $ tags ]) {
74
72
$ post = new Post ();
75
73
$ post ->setTitle ($ title );
@@ -132,21 +130,25 @@ private function getTagData(): array
132
130
/**
133
131
* @throws \Exception
134
132
*
135
- * @return array<int, array{0: string, 1: AbstractUnicodeString, 2: string, 3: string, 4: \DateTime, 5: object , 6: array<object >}>
133
+ * @return array<int, array{0: string, 1: AbstractUnicodeString, 2: string, 3: string, 4: \DateTime, 5: User , 6: array<Tag >}>
136
134
*/
137
135
private function getPostData (): array
138
136
{
139
137
$ posts = [];
140
138
foreach ($ this ->getPhrases () as $ i => $ title ) {
141
139
// $postData = [$title, $slug, $summary, $content, $publishedAt, $author, $tags, $comments];
140
+
141
+ /** @var User $user */
142
+ $ user = $ this ->getReference (['jane_admin ' , 'tom_admin ' ][0 === $ i ? 0 : random_int (0 , 1 )]);
143
+
142
144
$ posts [] = [
143
145
$ title ,
144
146
$ this ->slugger ->slug ($ title )->lower (),
145
147
$ this ->getRandomText (),
146
148
$ this ->getPostContent (),
147
149
new \DateTime ('now - ' .$ i .'days ' ),
148
150
// Ensure that the first post is written by Jane Doe to simplify tests
149
- $ this -> getReference ([ ' jane_admin ' , ' tom_admin ' ][ 0 === $ i ? 0 : random_int ( 0 , 1 )]) ,
151
+ $ user ,
150
152
$ this ->getRandomTags (),
151
153
];
152
154
}
@@ -249,14 +251,19 @@ private function getPostContent(): string
249
251
/**
250
252
* @throws \Exception
251
253
*
252
- * @return array<object >
254
+ * @return array<Tag >
253
255
*/
254
256
private function getRandomTags (): array
255
257
{
256
258
$ tagNames = $ this ->getTagData ();
257
259
shuffle ($ tagNames );
258
260
$ selectedTags = \array_slice ($ tagNames , 0 , random_int (2 , 4 ));
259
261
260
- return array_map (function ($ tagName ) { return $ this ->getReference ('tag- ' .$ tagName ); }, $ selectedTags );
262
+ return array_map (function ($ tagName ) {
263
+ /** @var Tag $tag */
264
+ $ tag = $ this ->getReference ('tag- ' .$ tagName );
265
+
266
+ return $ tag ;
267
+ }, $ selectedTags );
261
268
}
262
269
}
0 commit comments