CategoryFixtures   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCategoryData() 0 8 1
A load() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\DataFixtures;
6
7
use App\Entity\Category;
8
use Doctrine\Bundle\FixturesBundle\Fixture;
9
use Doctrine\Persistence\ObjectManager;
10
11
final class CategoryFixtures extends Fixture
12
{
13
    public function load(ObjectManager $manager): void
14
    {
15
        foreach ($this->getCategoryData() as [$slug, $name]) {
16
            $category = new Category();
17
            $category->setName($name);
18
            $category->setSlug($slug);
19
            $manager->persist($category);
20
            $this->addReference($name, $category);
21
        }
22
        $manager->flush();
23
    }
24
25
    private function getCategoryData(): array
26
    {
27
        return [
28
            // $categoryData = [$slug, $name];
29
            ['apartment', 'Apartment'],
30
            ['duplex', 'Duplex'],
31
            ['penthouse', 'Penthouse'],
32
            ['villa', 'Villa'],
33
        ];
34
    }
35
}
36