LoadFixturesCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
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