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

LocalityFixtures   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocalityData() 0 7 1
A load() 0 10 2
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