Passed
Push — master ( 75052b...8ecf83 )
by Dmitri
01:50
created

AuthorFixtures::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 16
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Doctrine\DataFixtures;
6
7
use App\Domain\Model\Author;
8
use App\Domain\Model\IdGenerator;
9
use Doctrine\Bundle\FixturesBundle\Fixture;
10
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
11
use Doctrine\Common\Persistence\ObjectManager;
12
13
final class AuthorFixtures extends Fixture implements OrderedFixtureInterface
14
{
15
    private $idGenerator;
16
17
    public function __construct(IdGenerator $idGenerator)
18
    {
19
        $this->idGenerator = $idGenerator;
20
    }
21
22
    public function getOrder(): int
23
    {
24
        return 100;
25
    }
26
27
    public function load(ObjectManager $manager): void
28
    {
29
        $data = [
30
            'shakespeare' => 'William Shakespeare',
31
            'christie' => 'Agatha Christie',
32
        ];
33
34
        foreach ($data as $alias => $fullName) {
35
            $author = new Author($this->idGenerator->authorId(), $fullName);
36
37
            $this->addReference('author-' . $alias, $author);
38
39
            $manager->persist($author);
40
        }
41
42
        $manager->flush();
43
    }
44
}
45