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

BookFixtures   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 59
dl 0
loc 130
rs 10
c 0
b 0
f 0
wmc 4
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\Book;
9
use App\Domain\Model\IdGenerator;
10
use Doctrine\Bundle\FixturesBundle\Fixture;
11
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
12
use Doctrine\Common\Persistence\ObjectManager;
13
14
final class BookFixtures extends Fixture implements OrderedFixtureInterface
15
{
16
    private $idGenerator;
17
18
    public function __construct(IdGenerator $idGenerator)
19
    {
20
        $this->idGenerator = $idGenerator;
21
    }
22
23
    public function getOrder(): int
24
    {
25
        return 200;
26
    }
27
28
    public function load(ObjectManager $manager): void
29
    {
30
        $data = [
31
            // Author 1
32
            [
33
                'title' => 'Antony and Cleopatra',
34
                'author' => 'shakespeare',
35
            ],
36
            [
37
                'title' => 'Coriolanus',
38
                'author' => 'shakespeare',
39
            ],
40
            [
41
                'title' => 'Hamlet',
42
                'author' => 'shakespeare',
43
            ],
44
            [
45
                'title' => 'Julius Caesar',
46
                'author' => 'shakespeare',
47
            ],
48
            [
49
                'title' => 'King Lear',
50
                'author' => 'shakespeare',
51
            ],
52
            [
53
                'title' => 'Macbeth',
54
                'author' => 'shakespeare',
55
            ],
56
            [
57
                'title' => 'Othello',
58
                'author' => 'shakespeare',
59
            ],
60
            [
61
                'title' => 'The Tragedy of Romeo and Juliet',
62
                'author' => 'shakespeare',
63
            ],
64
            [
65
                'title' => 'Timon of Athens',
66
                'author' => 'shakespeare',
67
            ],
68
            [
69
                'title' => 'Titus Andronicus',
70
                'author' => 'shakespeare',
71
            ],
72
            [
73
                'title' => 'Troilus and Cressida',
74
                'author' => 'shakespeare',
75
            ],
76
            [
77
                'title' => 'All\'s Well That Ends Well',
78
                'author' => 'shakespeare',
79
            ],
80
            [
81
                'title' => 'As You Like It',
82
                'author' => 'shakespeare',
83
            ],
84
            [
85
                'title' => 'The Comedy of Errors',
86
                'author' => 'shakespeare',
87
            ],
88
            [
89
                'title' => 'Cymbeline',
90
                'author' => 'shakespeare',
91
            ],
92
            [
93
                'title' => 'Love\'s Labour\'s Lost',
94
                'author' => 'shakespeare',
95
            ],
96
            [
97
                'title' => 'Measure for Measure',
98
                'author' => 'shakespeare',
99
            ],
100
101
            // Author 2
102
            [
103
                'title' => 'The Mysterious Affair at Styles',
104
                'author' => 'christie',
105
            ],
106
            [
107
                'title' => 'The Secret Adversary',
108
                'author' => 'christie',
109
            ],
110
            [
111
                'title' => 'The Murder on the Links',
112
                'author' => 'christie',
113
            ],
114
            [
115
                'title' => 'The Man in the Brown Suit',
116
                'author' => 'christie',
117
            ],
118
            [
119
                'title' => 'The Secret of Chimneys',
120
                'author' => 'christie',
121
            ],
122
            [
123
                'title' => 'The Murder of Roger Ackroyd',
124
                'author' => 'christie',
125
            ],
126
            [
127
                'title' => 'The Big Four',
128
                'author' => 'christie',
129
            ],
130
            [
131
                'title' => 'The Mystery of the Blue Train',
132
                'author' => 'christie',
133
            ],
134
        ];
135
136
        foreach ($data as $item) {
137
            /** @var Author $author */
138
            $author = $this->getReference('author-' . $item['author']);
139
140
            $manager->persist(new Book($this->idGenerator->bookId(), $author->id(), $item['title']));
141
        }
142
143
        $manager->flush();
144
    }
145
}
146