GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CreateCommand::execute()   C
last analyzed

Complexity

Conditions 7
Paths 25

Size

Total Lines 46
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 10
Bugs 2 Features 3
Metric Value
c 10
b 2
f 3
dl 0
loc 46
rs 6.7272
cc 7
eloc 35
nc 25
nop 2
1
<?php
2
3
namespace Czogori\DamiBundle\Command;
4
5
use Symfony\Component\Console\Input\InputArgument,
6
    Symfony\Component\Console\Input\InputInterface,
7
    Symfony\Component\Console\Output\OutputInterface,
8
    Symfony\Component\Filesystem\Filesystem;
9
10
use Dami\Migration\FileNameBuilder;
11
12
class CreateCommand extends AbstractCommand
13
{
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('dami:create')
18
            ->setDescription('Create a new migration.')
19
            ->setDefinition(array(
20
                new InputArgument('migration_name', InputArgument::REQUIRED, 'Migration name'),
21
                new InputArgument('bundle_name', InputArgument::REQUIRED, 'Bundle name'),
22
        ));
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $arguments = $input->getArguments();
28
        $migrationName = $arguments['migration_name'];
29
        $bundleName = $arguments['bundle_name'];
30
31
        $kernel = $this->getContainer()->get('kernel');
32
        $budleExists = false;
33
        foreach ($kernel->getBundles() as $bundle) {
34
            if ($bundle->getName() === $bundleName) {
35
                $bundleMigrationDirectory = $bundle->getPath() . '/Resources/migrations';
36
                $fileSystem = new Filesystem();
37
                if (!file_exists($bundleMigrationDirectory)) {
38
                    $output->writeln('<error>Directory of migrations does not exist.</error>');
39
40
                    $dialog = $this->getHelperSet()->get('dialog');
41
                    if(!$dialog->askConfirmation(
42
                        $output,
43
                        sprintf('<question>Do you want to create %s directory? (Y/n)</question>', $bundleMigrationDirectory),
44
                        true)) {
45
                            return;
46
                    }
47
                    $fileSystem->mkdir($bundleMigrationDirectory);
48
                    $output->writeln('<info>Directory of migrations has been created.</info>');
49
                    $output->writeln(sprintf('<comment>Location: %s</comment>', $bundleMigrationDirectory));
50
                }
51
                $filenameBuilder = new FileNameBuilder($migrationName);
52
                $templateRenderer = $this->getContainer()->get('dami.template_renderer');
53
                try {
54
                    $fileName = $filenameBuilder->build();
55
                    $path = $bundleMigrationDirectory . '/' . $fileName;
56
                    $fileSystem->dumpFile($path, $templateRenderer->render($migrationName));
57
58
                    $output->writeln('<info>Migration has been created.</info>');
59
                    $output->writeln(sprintf('<comment>Location: %s</comment>', $path));
60
                } catch (\Exception $e) {
61
                    $output->writeln(sprintf("<error>Something went wrong.</error>\n\n%s", $e->getMessage()));
62
                }
63
                $budleExists = true;
64
                break;
65
            }
66
        }
67
        if (false === $budleExists) {
68
            $output->writeln(sprintf('<comment>Bundle %s does not exist.</comment>', $bundleName));
69
        }
70
    }
71
}
72