Completed
Push — feature/VSVGVQ-23 ( 35ff00 )
by Luc
02:42
created

SeedCategoriesCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 4 1
B createCategories() 0 34 1
A execute() 0 11 2
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Command;
4
5
use Ramsey\Uuid\Uuid;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use VSV\GVQ_API\Question\Models\Categories;
10
use VSV\GVQ_API\Question\Models\Category;
11
use VSV\GVQ_API\Question\Repositories\CategoryRepository;
12
use VSV\GVQ_API\Question\ValueObjects\NotEmptyString;
13
14
class SeedCategoriesCommand extends Command
15
{
16
    /**
17
     * @var CategoryRepository
18
     */
19
    private $categoriesRepository;
20
21
    /**
22
     * @param CategoryRepository $categoriesRepository
23
     */
24
    public function __construct(CategoryRepository $categoriesRepository)
25
    {
26
        parent::__construct();
27
        $this->categoriesRepository = $categoriesRepository;
28
    }
29
30
    protected function configure(): void
31
    {
32
        $this->setName('gvq:seed-categories')
33
            ->setDescription('Upload all categories');
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output): void
40
    {
41
        $output->writeln('Seeding categories...');
42
43
        $categories = $this->createCategories()->toArray();
44
        foreach ($categories as $category) {
45
            $output->writeln('Seeding category: '.$category->getName()->toNative());
46
            $this->categoriesRepository->save($category);
47
        }
48
49
        $output->writeln('Seeding finished.');
50
    }
51
52
    /**
53
     * @return Categories
54
     */
55
    private function createCategories(): Categories
56
    {
57
        return new Categories(
58
            new Category(
59
                Uuid::fromString('a7910bf1-05f9-4bdb-8dee-1256cbfafc0b'),
60
                new NotEmptyString('Algemene verkeersregels')
61
            ),
62
            new Category(
63
                Uuid::fromString('15530c78-2b1c-4820-bcfb-e04c5e2224b9'),
64
                new NotEmptyString('Kwetsbare weggebruikers')
65
            ),
66
            new Category(
67
                Uuid::fromString('67844067-82ca-4698-a713-b5fbd4c729c5'),
68
                new NotEmptyString('Verkeerstekens')
69
            ),
70
            new Category(
71
                Uuid::fromString('58ee6bd3-a3f4-42bc-ba81-82491cec55b9'),
72
                new NotEmptyString('Voorrang')
73
            ),
74
            new Category(
75
                Uuid::fromString('1289d4b5-e88e-4b3c-9223-eb2c7c49f4d0'),
76
                new NotEmptyString('EHBO/Ongeval/Verzekering')
77
            ),
78
            new Category(
79
                Uuid::fromString('9677995d-5fc5-48cd-a251-565b626cb7c1'),
80
                new NotEmptyString('Voertuig/Techniek')
81
            ),
82
            new Category(
83
                Uuid::fromString('fce11f3c-24ad-4aed-b00d-0069e3404749'),
84
                new NotEmptyString('Openbaar vervoer/Milieu')
85
            ),
86
            new Category(
87
                Uuid::fromString('6f0c9e04-1e84-4ba4-be54-ab5747111754'),
88
                new NotEmptyString('Verkeersveiligheid')
89
            )
90
        );
91
    }
92
}
93