LoadFixturesCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 12
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 11 1
A __construct() 0 5 1
1
<?php
2
/**
3
 * Copyright (c) 2020.
4
 * @author Paweł Antosiak <[email protected]>
5
 */
6
7
declare(strict_types=1);
8
9
namespace Gorynych\Command;
10
11
use Gorynych\Adapter\EntityManagerAdapterInterface;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Style\SymfonyStyle;
17
18
final class LoadFixturesCommand extends Command
19
{
20
    protected static $defaultName = 'gorynych:load-fixtures';
21
22
    private EntityManagerAdapterInterface $entityManager;
23
24
    public function __construct(EntityManagerAdapterInterface $managerAdapter)
25
    {
26
        parent::__construct();
27
28
        $this->entityManager = $managerAdapter;
29
    }
30
31
    protected function configure(): void
32
    {
33
        $this
34
            ->setDescription('Loads fixtures into database for specified environment (dev by default).')
35
            ->addOption('env', 'e', InputArgument::OPTIONAL);
36
    }
37
38
    protected function execute(InputInterface $input, OutputInterface $output): int
39
    {
40
        $env = $input->getOption('env') ?? 'dev';
41
42
        $io = new SymfonyStyle($input, $output);
43
        $io->confirm("Using {$env} envirenment. Continue?", true);
44
45
        $fixturesLoaded = $this->entityManager->loadFixtures(["_{$env}.yaml"]);
46
        $io->success("Fixtures loaded: {$fixturesLoaded}");
47
48
        return 0;
49
    }
50
}
51