Passed
Pull Request — develop (#95)
by BENARD
13:04 queued 39s
created

PlayerStatusFixtures::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\DataFixtures;
6
7
use Doctrine\Bundle\FixturesBundle\Fixture;
8
use Doctrine\ORM\Mapping\ClassMetadataInfo;
9
use Doctrine\Persistence\ObjectManager;
10
use Exception;
11
use VideoGamesRecords\CoreBundle\Entity\Player;
12
use VideoGamesRecords\CoreBundle\Entity\PlayerStatus;
13
14
class PlayerStatusFixtures extends Fixture
15
{
16
    /**
17
     * @var array<string>
18
     */
19
    private array $entities = [
20
        'PlayerStatus',
21
    ];
22
23
    private function updateGeneratorType(ObjectManager $manager): void
24
    {
25
        foreach ($this->entities as $entity) {
26
            $metadata = $manager->getClassMetaData("VideoGamesRecords\\CoreBundle\\Entity\\" . $entity);
27
            $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
28
        }
29
    }
30
31
    /**
32
     * @throws Exception
33
     */
34
    public function load(ObjectManager $manager): void
35
    {
36
        $this->updateGeneratorType($manager);
37
        $this->loadStatus($manager);
38
        $manager->flush();
39
    }
40
41
42
    /**
43
     * @param $manager
44
     */
45
    public function loadStatus($manager): void
46
    {
47
        $playerStatus = new PlayerStatus();
48
        $playerStatus->setId(1);
49
        $playerStatus->setClass('normal');
50
        $manager->persist($playerStatus);
51
        $this->addReference('playerStatus1', $playerStatus);
52
    }
53
}
54