Conditions | 8 |
Paths | 38 |
Total Lines | 58 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
77 | protected function execute(InputInterface $input, OutputInterface $output) |
||
78 | { |
||
79 | $fileSystem = new Filesystem(); |
||
80 | $kernel = $this->getContainer()->get('kernel'); |
||
81 | $name = $input->getArgument('name'); |
||
82 | $helper = $this->getHelper('question'); |
||
83 | $force = true === $input->getOption('force'); |
||
84 | |||
85 | if (!$name) { |
||
86 | $name = $this->getActiveThemeName(); |
||
87 | } |
||
88 | |||
89 | try { |
||
90 | if ($input->getOption('delete')) { |
||
91 | $question = new ConfirmationQuestion( |
||
92 | '<question>This will override your current theme: "'.$name.'", if exists. Continue with this action? (yes/no)<question> <comment>[yes]</comment> ', |
||
93 | true, |
||
94 | '/^(y|j)/i' |
||
95 | ); |
||
96 | |||
97 | if (!$force) { |
||
98 | if (!$helper->ask($input, $output, $question)) { |
||
99 | return; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | $fileSystem->remove($kernel->getRootDir().'/Resources/themes/'.$name); |
||
104 | |||
105 | $output->writeln('<info>Theme "'.$name.'" has been deleted successfully!</info>'); |
||
106 | |||
107 | return true; |
||
108 | } |
||
109 | |||
110 | $question = new ConfirmationQuestion( |
||
111 | '<question>This will override your current theme: "'.$name.'", if exists. Continue with this action? (yes/no)<question> <comment>[yes]</comment> ', |
||
112 | true, |
||
113 | '/^(y|j)/i' |
||
114 | ); |
||
115 | |||
116 | if (!$force) { |
||
117 | if (!$helper->ask($input, $output, $question)) { |
||
118 | return; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | $fileSystem->mirror( |
||
123 | $kernel->locateResource('@SWPFixturesBundle/Resources/themes/'.self::DEFAULT_THEME_NAME), |
||
124 | $kernel->getRootDir().'/Resources/themes/'.$name, |
||
125 | null, |
||
126 | ['override' => true, 'delete' => true] |
||
127 | ); |
||
128 | |||
129 | $output->writeln('<info>Theme "'.$name.'" has been setup successfully!</info>'); |
||
130 | } catch (\Exception $e) { |
||
131 | $output->writeln('<error>Theme "'.$name.'" could not be setup!</error>'); |
||
132 | $output->writeln('<error>Stacktrace: '.$e->getMessage().'</error>'); |
||
133 | } |
||
134 | } |
||
135 | |||
141 |