Completed
Push — master ( a81a90...8dc74b )
by Valery
04:17
created

LocalityFixtures::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\DataFixtures;
6
7
use App\Entity\Locality;
8
use Doctrine\Bundle\FixturesBundle\Fixture;
9
use Doctrine\Common\Persistence\ObjectManager;
10
11
class LocalityFixtures extends Fixture
12
{
13
    public function load(ObjectManager $manager): void
14
    {
15
        foreach ($this->getLocalityData() as [$slug, $name]) {
16
            $locality = new Locality();
17
            $locality->setName($name);
18
            $locality->setSlug($slug);
19
            $manager->persist($locality);
20
            $this->addReference($name, $locality);
21
        }
22
        $manager->flush();
23
    }
24
25
    private function getLocalityData(): array
26
    {
27
        return [
28
            // $localityData = [$slug, $name];
29
            ['miami', 'Miami'],
30
            ['palm-beach', 'Palm Beach'],
31
            ['tampa', 'Tampa'],
32
        ];
33
    }
34
}
35