Issues (5)

src/DataFixtures/TrickFixtures.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\DataFixtures;
4
5
use App\Entity\Category;
6
use App\Entity\Image;
7
use App\Entity\Trick;
8
use Doctrine\Bundle\FixturesBundle\Fixture;
9
use Doctrine\Common\Persistence\ObjectManager;
10
use Faker\Factory;
11
12
class TrickFixtures extends Fixture
13
{
14
    public function load(ObjectManager $manager)
15
    {
16
        $faker = Factory::create();
17
18
        $categoryList = array();
19
        for($i=0; $i<5; $i++){
20
            $category = new Category();
21
            $categoryList[] = $category->setName($faker->sentence(5));
22
            $manager->persist($category);
23
        }
24
25
        for ($i=0; $i<25; $i++){
26
            $trick = new Trick();
27
            $trick
28
                ->setName($faker->words(rand(1,5), true))
0 ignored issues
show
It seems like $faker->words(rand(1, 5), true) can also be of type array; however, parameter $name of App\Entity\Trick::setName() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
                ->setName(/** @scrutinizer ignore-type */ $faker->words(rand(1,5), true))
Loading history...
29
                ->setText($faker->paragraph(rand(3,20)))
30
                ->setCreatedAt($faker->dateTimeThisDecade())
31
                ->setCategory($categoryList[rand(0,4)])
32
            ;
33
34
            $manager->persist($trick);
35
            $manager->flush();
36
            //var_dump($trick->getId()); //use this for the trick images folder
37
38
            //create associated images
39
//            for ($i=0; $i < rand(0,6); $i++){
40
//                $image = new Image();
41
//                $image->setTitle($faker->word(rand(1,7), true));
42
//                //error if the folder doesn't exist. make folder with trick ID
43
//                $image->setImage($faker->image('public/uploads/images/'.$trick->getId().'/', 400, 300, null, false));
44
//            }
45
        }
46
47
        $manager->flush();
48
    }
49
}
50