MetroFixtures   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetroData() 0 8 1
A load() 0 11 2
A getDependencies() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\DataFixtures;
6
7
use App\Entity\Metro;
8
use Doctrine\Bundle\FixturesBundle\Fixture;
9
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
10
use Doctrine\Persistence\ObjectManager;
11
12
final class MetroFixtures extends Fixture implements DependentFixtureInterface
13
{
14
    public function load(ObjectManager $manager): void
15
    {
16
        foreach ($this->getMetroData() as [$city, $name, $slug]) {
17
            $metro = new Metro();
18
            $metro->setCity($city);
19
            $metro->setName($name);
20
            $metro->setSlug($slug);
21
            $manager->persist($metro);
22
            $this->addReference($name, $metro);
23
        }
24
        $manager->flush();
25
    }
26
27
    private function getMetroData(): array
28
    {
29
        return [
30
            // $metroData = [$city, $name, $slug];
31
           [$this->getReference('Miami'), 'Government Center', 'government-center'],
32
           [$this->getReference('Miami'), 'Allapattah', 'allapattah'],
33
           [$this->getReference('Miami'), 'Brickell', 'brickell'],
34
           [$this->getReference('Miami'), 'Culmer', 'culmer'],
35
        ];
36
    }
37
38
    public function getDependencies()
39
    {
40
        return [
41
            CityFixtures::class,
42
        ];
43
    }
44
}
45