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\AdminTestsGenerator; |
||
6 | use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils; |
||
7 | use Kunstmaan\GeneratorBundle\Helper\Sf4AppBundle; |
||
8 | use Sensio\Bundle\GeneratorBundle\Command\GeneratorCommand; |
||
9 | use Sensio\Bundle\GeneratorBundle\Command\Validators; |
||
10 | use Symfony\Component\Console\Input\InputInterface; |
||
11 | use Symfony\Component\Console\Input\InputOption; |
||
12 | use Symfony\Component\Console\Output\OutputInterface; |
||
13 | use Symfony\Component\HttpKernel\Kernel; |
||
14 | |||
15 | /** |
||
16 | * GenerateAdminTestsCommand |
||
17 | */ |
||
18 | class GenerateAdminTestsCommand extends GeneratorCommand |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | protected function configure() |
||
24 | { |
||
25 | $this |
||
26 | ->setDefinition( |
||
27 | array( |
||
28 | new InputOption('namespace', '', InputOption::VALUE_REQUIRED, 'The namespace to generate the tests in'), |
||
29 | ) |
||
30 | ) |
||
31 | ->setDescription('Generates the tests used to test the admin created by the default-site generator') |
||
32 | ->setHelp(<<<'EOT' |
||
33 | The <info>kuma:generate:admin-test</info> command generates tests to test the admin generated by the default-site generator |
||
34 | |||
35 | <info>php bin/console kuma:generate:admin-tests --namespace=Namespace/NamedBundle</info> |
||
36 | |||
37 | EOT |
||
38 | ) |
||
39 | ->setName('kuma:generate:admin-tests'); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | protected function execute(InputInterface $input, OutputInterface $output) |
||
46 | { |
||
47 | $questionHelper = $this->getQuestionHelper(); |
||
48 | $questionHelper->writeSection($output, 'Admin Tests Generation'); |
||
49 | |||
50 | $bundle = new Sf4AppBundle($this->getContainer()->getParameter('kernel.project_dir')); |
||
51 | if (Kernel::VERSION_ID < 40000) { |
||
52 | GeneratorUtils::ensureOptionsProvided($input, ['namespace']); |
||
53 | |||
54 | $namespace = Validators::validateBundleNamespace($input->getOption('namespace')); |
||
55 | $bundle = strtr($namespace, ['\\Bundle\\' => '', '\\' => '']); |
||
56 | |||
57 | $bundle = $this |
||
58 | ->getApplication() |
||
59 | ->getKernel() |
||
60 | ->getBundle($bundle); |
||
61 | } |
||
62 | |||
63 | $generator = $this->getGenerator($this->getApplication()->getKernel()->getBundle('KunstmaanGeneratorBundle')); |
||
64 | $generator->generate($bundle, $output); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | View Code Duplication | protected function interact(InputInterface $input, OutputInterface $output) |
|
0 ignored issues
–
show
|
|||
71 | { |
||
72 | if (Kernel::VERSION_ID >= 40000) { |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $questionHelper = $this->getQuestionHelper(); |
||
77 | $questionHelper->writeSection($output, 'Welcome to the Kunstmaan default site generator'); |
||
78 | |||
79 | $inputAssistant = GeneratorUtils::getInputAssistant($input, $output, $questionHelper, $this->getApplication()->getKernel(), $this->getContainer()); |
||
80 | |||
81 | $inputAssistant->askForNamespace(array( |
||
82 | '', |
||
83 | 'This command helps you to generate tests to test the admin of the default site setup.', |
||
84 | 'You must specify the namespace of the bundle where you want to generate the tests.', |
||
85 | 'Use <comment>/</comment> instead of <comment>\\ </comment>for the namespace delimiter to avoid any problem.', |
||
86 | '', |
||
87 | )); |
||
88 | } |
||
89 | |||
90 | protected function createGenerator() |
||
91 | { |
||
92 | return new AdminTestsGenerator($this->getContainer(), $this->getContainer()->get('filesystem'), '/admintests'); |
||
93 | } |
||
94 | } |
||
95 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.