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()->getProjectDir().'/'; |
||
0 ignored issues
–
show
|
|||
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 | return 0; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | protected function doInteract() |
||
78 | { |
||
79 | if (!$this->isSubCommand()) { |
||
80 | $this->assistant->writeLine(array("This command helps you to generate a basic layout for your website.\n")); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Ask for which bundle we need to create the layout |
||
85 | */ |
||
86 | $bundleNamespace = $this->assistant->getOptionOrDefault('namespace', null); |
||
87 | $this->bundle = $this->askForBundleName('layout', $bundleNamespace); |
||
0 ignored issues
–
show
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...
|
|||
88 | $this->browserSyncUrl = $this->assistant->getOptionOrDefault('browsersync', null); |
||
89 | |||
90 | if (null === $this->browserSyncUrl) { |
||
91 | $this->browserSyncUrl = $this->assistant->ask('Which URL would you like to configure for browserSync?', 'http://myproject.dev'); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Get the generator. |
||
97 | * |
||
98 | * @return LayoutGenerator |
||
99 | */ |
||
100 | View Code Duplication | protected function createGenerator() |
|
101 | { |
||
102 | $filesystem = $this->getContainer()->get('filesystem'); |
||
103 | $registry = $this->getContainer()->get('doctrine'); |
||
104 | |||
105 | return new LayoutGenerator($filesystem, $registry, '/layout', $this->assistant, $this->getContainer()); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Check that the command is ran as sub command or not. |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | private function isSubCommand() |
||
114 | { |
||
115 | return $this->assistant->getOptionOrDefault('subcommand', false); |
||
116 | } |
||
117 | } |
||
118 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: