@@ -54,7 +54,10 @@ public function load(ObjectManager $manager)
54
54
$ post ->setAuthor ($ this ->getReference ('jane-admin ' ));
55
55
$ post ->setPublishedAt (new \DateTime ('now - ' .$ i .'days ' ));
56
56
57
- $ this ->addRandomTags ($ post );
57
+ // for aesthetic reasons, the first blog post always has 2 tags
58
+ foreach ($ this ->getRandomTags ($ i > 0 ? mt_rand (0 , 3 ) : 2 ) as $ tag ) {
59
+ $ post ->addTag ($ tag );
60
+ }
58
61
59
62
foreach (range (1 , 5 ) as $ j ) {
60
63
$ comment = new Comment ();
@@ -89,18 +92,20 @@ public function getDependencies()
89
92
];
90
93
}
91
94
92
- private function addRandomTags ( Post $ post )
95
+ private function getRandomTags ( $ numTags = 0 )
93
96
{
94
- if (0 === $ count = mt_rand (0 , 3 )) {
95
- return ;
97
+ $ tags = [];
98
+
99
+ if (0 === $ numTags ) {
100
+ return $ tags ;
96
101
}
97
102
98
- $ indexes = (array ) array_rand (TagFixtures::$ names , $ count );
103
+ $ indexes = (array ) array_rand (TagFixtures::$ names , $ numTags );
99
104
foreach ($ indexes as $ index ) {
100
- /** @var Tag $tag */
101
- $ tag = $ this ->getReference ('tag- ' .$ index );
102
- $ post ->addTag ($ tag );
105
+ $ tags [] = $ this ->getReference ('tag- ' .$ index );
103
106
}
107
+
108
+ return $ tags ;
104
109
}
105
110
106
111
private function getPostContent ()
@@ -197,8 +202,13 @@ private function getRandomPostSummary($maxLength = 255)
197
202
198
203
$ numPhrases = mt_rand (6 , 12 );
199
204
shuffle ($ phrases );
205
+ $ phrases = array_slice ($ phrases , 0 , $ numPhrases - 1 );
206
+
207
+ while (strlen ($ summary = implode ('. ' , $ phrases ).'. ' ) > $ maxLength ) {
208
+ array_pop ($ phrases );
209
+ }
200
210
201
- return substr ( implode ( ' ' , array_slice ( $ phrases , 0 , $ numPhrases - 1 )), 0 , $ maxLength ) ;
211
+ return $ summary ;
202
212
}
203
213
204
214
private function getRandomCommentContent ()
0 commit comments