NeighborhoodFixtures::getNeighborhoodData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\DataFixtures;
6
7
use App\Entity\Neighborhood;
8
use Doctrine\Bundle\FixturesBundle\Fixture;
9
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
10
use Doctrine\Persistence\ObjectManager;
11
12
final class NeighborhoodFixtures extends Fixture implements DependentFixtureInterface
13
{
14
    public function load(ObjectManager $manager): void
15
    {
16
        foreach ($this->getNeighborhoodData() as [$city, $name, $slug]) {
17
            $neighborhood = new Neighborhood();
18
            $neighborhood->setCity($city);
19
            $neighborhood->setName($name);
20
            $neighborhood->setSlug($slug);
21
            $manager->persist($neighborhood);
22
            $this->addReference($name, $neighborhood);
23
        }
24
        $manager->flush();
25
    }
26
27
    private function getNeighborhoodData(): array
28
    {
29
        return [
30
            // $neighborhoodData = [$city, $name, $slug];
31
           [$this->getReference('Miami'), 'South Beach', 'south-beach'],
32
           [$this->getReference('Miami'), 'Downtown', 'downtown'],
33
           [$this->getReference('Tampa'), 'Ballast Point', 'ballast-point'],
34
           [$this->getReference('Tampa'), 'Culbreath Isles', 'culbreath-isles'],
35
        ];
36
    }
37
38
    public function getDependencies()
39
    {
40
        return [
41
            CityFixtures::class,
42
        ];
43
    }
44
}
45