| Conditions | 6 |
| Paths | 3 |
| Total Lines | 35 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 33 | public function load(ObjectManager $manager) |
||
| 34 | { |
||
| 35 | $faker = Factory::create(); |
||
| 36 | |||
| 37 | $tricks = $manager->getRepository(Trick::class)->findAll(); |
||
| 38 | $tagRepository = $manager->getRepository(Tag::class); |
||
| 39 | |||
| 40 | $fixedTag = new Tag(); |
||
| 41 | $fixedTag->setName("Starbug tag"); |
||
| 42 | |||
| 43 | foreach ($tricks as $trick){ |
||
| 44 | $maxTags = rand(0,5); |
||
| 45 | if($maxTags >0){ |
||
| 46 | for($i=0; $i<=$maxTags; $i++){ |
||
| 47 | |||
| 48 | $tagName = $faker->words(rand(1,3), true); |
||
| 49 | //Avoid duplicate tags |
||
| 50 | $tag = $tagRepository->findOneBy(['name'=>$tagName]); |
||
| 51 | if($tag === null){ |
||
| 52 | $tag=new Tag(); |
||
| 53 | $tag->setName($tagName); |
||
|
|
|||
| 54 | } |
||
| 55 | |||
| 56 | $trick->addTag($tag); |
||
| 57 | |||
| 58 | if(rand(0,6)===1){ |
||
| 59 | $trick->addTag($fixedTag); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | $manager->persist($trick); |
||
| 64 | $manager->flush(); //need to flush or next DB query for unicity will fail |
||
| 65 | } |
||
| 66 | |||
| 67 | $manager->flush(); |
||
| 68 | |||
| 70 | } |