| Conditions | 6 |
| Paths | 12 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 51 | public function getInstallDatabase(ServerRequestInterface $request, ResponseInterface $response, $args) |
||
| 52 | { |
||
| 53 | $this->logger->info("Fetch database install GET '/install/database'"); |
||
| 54 | |||
| 55 | try { |
||
| 56 | $existingUserCount = UserQuery::create()->count(); |
||
| 57 | if ($existingUserCount > 0) { |
||
| 58 | return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('login')); |
||
| 59 | } |
||
| 60 | } catch (\Propel\Runtime\Exception\PropelException $e) { |
||
| 61 | if ($e->getPrevious()->getCode() !== '42S02') { |
||
| 62 | return $response; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | $site = new Site(); |
||
| 67 | $config = $site->getConfig(); |
||
| 68 | |||
| 69 | $propelGenerator = new Application('Propel', Propel::VERSION); |
||
| 70 | $propelGenerator->setAutoExit(false); |
||
| 71 | $propelGenerator->add(new \Propel\Generator\Command\SqlBuildCommand()); |
||
| 72 | $propelGenerator->add(new \Propel\Generator\Command\SqlInsertCommand()); |
||
| 73 | |||
| 74 | $output = new BufferedOutput(); |
||
| 75 | |||
| 76 | $input = new ArrayInput([ |
||
| 77 | 'command' => 'sql:build', |
||
| 78 | '-vvv' => true, |
||
| 79 | '--overwrite' => true, |
||
| 80 | '--config-dir' => __DIR__.'/../../../generated-conf', |
||
| 81 | '--schema-dir' => __DIR__.'/../../../', |
||
| 82 | '--output-dir' => __DIR__.'/../../../build/sql', |
||
| 83 | ]); |
||
| 84 | $propelGenerator->run($input, $output); |
||
| 85 | |||
| 86 | $input = new ArrayInput([ |
||
| 87 | 'command' => 'sql:insert', |
||
| 88 | '-vvv' => true, |
||
| 89 | '--config-dir' => __DIR__.'/../../../generated-conf', |
||
| 90 | '--sql-dir' => __DIR__.'/../../../build/sql', |
||
| 91 | ]); |
||
| 92 | $propelGenerator->run($input, $output); |
||
| 93 | |||
| 94 | $outputString = $output->fetch(); |
||
| 95 | $this->logger->info($outputString); |
||
| 96 | |||
| 97 | // check it was a success |
||
| 98 | try { |
||
| 99 | $existingUserCount = UserQuery::create()->count(); |
||
| 100 | } catch (\Propel\Runtime\Exception\PropelException $e) { |
||
| 101 | if ($e->getPrevious()->getCode() === '42S02') { |
||
| 102 | return $response->getBody()->write('Error installing database:'."\n".$outputString); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('install')); |
||
| 107 | } |
||
| 108 | |||
| 211 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.