| Conditions | 7 |
| Paths | 23 |
| Total Lines | 70 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 56 |
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 |
||
| 87 | protected function updateKernel( |
||
| 88 | QuestionHelper $questionHelper, |
||
| 89 | InputInterface $input, |
||
| 90 | OutputInterface $output, |
||
| 91 | KernelInterface $kernel, |
||
| 92 | $namespace, |
||
| 93 | $bundle |
||
| 94 | ) { |
||
| 95 | |||
| 96 | // skip if kernel manipulation disabled by options (defaults to true) |
||
| 97 | $doUpdate = $input->getOption('doUpdateKernel'); |
||
| 98 | if ($doUpdate == 'false') { |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | $auto = true; |
||
| 103 | if ($input->isInteractive()) { |
||
| 104 | $auto = $questionHelper->doAsk( |
||
| 105 | $output, |
||
| 106 | $questionHelper->getQuestion( |
||
| 107 | 'Confirm automatic update of your core bundle', |
||
| 108 | 'yes', |
||
| 109 | '?' |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 114 | $output->write('Enabling the bundle inside the core bundle: '); |
||
| 115 | $coreBundle = $kernel->getBundle($input->getOption('loaderBundleName')); |
||
| 116 | if (!is_a( |
||
| 117 | $coreBundle, |
||
| 118 | '\Graviton\BundleBundle\GravitonBundleInterface' |
||
| 119 | ) |
||
| 120 | ) { |
||
| 121 | throw new \LogicException( |
||
| 122 | 'GravitonCoreBundle does not implement GravitonBundleInterface' |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | $manip = new BundleBundleManipulator($coreBundle); |
||
| 126 | try { |
||
| 127 | $ret = $auto ? $manip->addBundle($namespace . '\\' . $bundle) : false; |
||
| 128 | |||
| 129 | if (!$ret) { |
||
| 130 | $reflected = new \ReflectionObject($kernel); |
||
| 131 | |||
| 132 | return array( |
||
| 133 | sprintf( |
||
| 134 | '- Edit <comment>%s</comment>', |
||
| 135 | $reflected->getFilename() |
||
| 136 | ), |
||
| 137 | ' and add the following bundle in the <comment>GravitonCoreBundle::getBundles()</comment> method:', |
||
| 138 | '', |
||
| 139 | sprintf( |
||
| 140 | ' <comment>new %s(),</comment>', |
||
| 141 | $namespace . '\\' . $bundle |
||
| 142 | ), |
||
| 143 | '' |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | } catch (\RuntimeException $e) { |
||
| 147 | return array( |
||
| 148 | sprintf( |
||
| 149 | 'Bundle <comment>%s</comment> is already defined in <comment>%s)</comment>.', |
||
| 150 | $namespace . '\\' . $bundle, |
||
| 151 | 'sGravitonCoreBundle::getBundles()' |
||
| 152 | ), |
||
| 153 | '' |
||
| 154 | ); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 191 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.