Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

GeneratorBundle/Command/GenerateLayoutCommand.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\GeneratorBundle\Command;
4
5
use Kunstmaan\GeneratorBundle\Generator\LayoutGenerator;
6
use Symfony\Component\Console\Input\InputOption;
7
8
/**
9
 * Generates de default layout
10
 */
11
class GenerateLayoutCommand extends KunstmaanGenerateCommand
12
{
13
    /**
14
     * @var BundleInterface
15
     */
16
    private $bundle;
17
18
    private $browserSyncUrl;
19
20
    /**
21
     * @see Command
22
     */
23
    protected function configure()
24
    {
25
        $this->setDescription('Generates a basic layout')
26
            ->setHelp(<<<EOT
27
The <info>kuma:generate:layout</info> command generates a basic website layout.
28
29
<info>php bin/console kuma:generate:layout</info>
30
31
Use the <info>--namespace</info> option to indicate for which bundle you want to create the layout
32
33
<info>php bin/console kuma:generate:layout --namespace=Namespace/NamedBundle</info>
34
EOT
35
            )
36
            ->addOption('namespace', '', InputOption::VALUE_OPTIONAL, 'The namespace of the bundle where we need to create the layout in')
37
            ->addOption('subcommand', '', InputOption::VALUE_OPTIONAL, 'Whether the command is called from an other command or not')
38
            ->addOption('demosite', '', InputOption::VALUE_NONE, 'Pass this parameter when the demosite styles/javascipt should be generated')
39
            ->addOption('browsersync', '', InputOption::VALUE_OPTIONAL, 'The URI that will be used for browsersync to connect')
40
            ->setName('kuma:generate:layout');
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function getWelcomeText()
47
    {
48
        if (!$this->isSubCommand()) {
49
            return 'Welcome to the Kunstmaan layout generator';
50
        } else {
51
            return null;
52
        }
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function doExecute()
59
    {
60
        if (!$this->isSubCommand()) {
61
            $this->assistant->writeSection('Layout generation');
62
        }
63
64
        $rootDir = $this->getApplication()->getKernel()->getRootDir().'/../';
65
        $this->createGenerator()->generate($this->bundle, $rootDir, $this->assistant->getOption('demosite'), $this->browserSyncUrl);
66
67
        if (!$this->isSubCommand()) {
68
            $this->assistant->writeSection('Layout successfully created', 'bg=green;fg=black');
69
        }
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    protected function doInteract()
76
    {
77
        if (!$this->isSubCommand()) {
78
            $this->assistant->writeLine(array("This command helps you to generate a basic layout for your website.\n"));
79
        }
80
81
        /**
82
         * Ask for which bundle we need to create the layout
83
         */
84
        $bundleNamespace = $this->assistant->getOptionOrDefault('namespace', null);
85
        $this->bundle = $this->askForBundleName('layout', $bundleNamespace);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->askForBundleName(...out', $bundleNamespace) of type object<Symfony\Component...Bundle\BundleInterface> is incompatible with the declared type object<Kunstmaan\Generat...ommand\BundleInterface> of property $bundle.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
86
        $this->browserSyncUrl = $this->assistant->getOptionOrDefault('browsersync', null);
87
88
        if (null === $this->browserSyncUrl) {
89
            $this->browserSyncUrl = $this->assistant->ask('Which URL would you like to configure for browserSync?', 'http://myproject.dev');
90
        }
91
    }
92
93
    /**
94
     * Get the generator.
95
     *
96
     * @return LayoutGenerator
97
     */
98
    protected function createGenerator()
99
    {
100
        $filesystem = $this->getContainer()->get('filesystem');
101
        $registry = $this->getContainer()->get('doctrine');
102
103
        return new LayoutGenerator($filesystem, $registry, '/layout', $this->assistant);
104
    }
105
106
    /**
107
     * Check that the command is ran as sub command or not.
108
     *
109
     * @return bool
110
     */
111
    private function isSubCommand()
112
    {
113
        return $this->assistant->getOptionOrDefault('subcommand', false);
114
    }
115
}
116