| Conditions | 7 |
| Paths | 24 |
| Total Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 60 | protected function interact(InputInterface $input, OutputInterface $output) |
||
| 61 | { |
||
| 62 | $this->io->title('EC-CUBE Installer Interactive Wizard'); |
||
| 63 | $this->io->text([ |
||
| 64 | 'If you prefer to not use this interactive wizard, define the environment valiables as follows:', |
||
| 65 | '', |
||
| 66 | ' $ export APP_ENV=dev', |
||
| 67 | ' $ export APP_DEBUG=1', |
||
| 68 | ' $ export DATABASE_URL=database_url', |
||
| 69 | ' $ export DATABASE_SERVER_VERSION=server_version', |
||
| 70 | ' $ export MAILER_URL=mailer_url', |
||
| 71 | ' $ export ECCUBE_AUTH_MAGIC=auth_magic', |
||
| 72 | ' ... and more', |
||
| 73 | ' $ php bin/console eccube:install --no-interaction', |
||
| 74 | '', |
||
| 75 | ]); |
||
| 76 | |||
| 77 | // DATABASE_URL |
||
| 78 | $databaseUrl = $this->container->getParameter('eccube_database_url'); |
||
| 79 | if (empty($databaseUrl)) { |
||
| 80 | $databaseUrl = 'sqlite:///var/eccube.db'; |
||
| 81 | } |
||
| 82 | $databaseUrl = $this->io->ask('Database Url', $databaseUrl); |
||
| 83 | |||
| 84 | // DATABASE_SERVER_VERSION |
||
| 85 | $serverVersion = $this->getDatabaseServerVersion($databaseUrl); |
||
| 86 | |||
| 87 | // MAILER_URL |
||
| 88 | $mailerUrl = $this->container->getParameter('eccube_mailer_url'); |
||
| 89 | if (empty($mailerUrl)) { |
||
| 90 | $mailerUrl = 'null://localhost'; |
||
| 91 | } |
||
| 92 | $mailerUrl = $this->io->ask('Mailer Url', $mailerUrl); |
||
| 93 | |||
| 94 | // ECCUBE_AUTH_MAGIC |
||
| 95 | $authMagic = $this->container->getParameter('eccube_auth_magic'); |
||
| 96 | if (empty($authMagic) || $authMagic === '<change.me>') { |
||
| 97 | $authMagic = StringUtil::random(); |
||
| 98 | } |
||
| 99 | $authMagic = $this->io->ask('Auth Magic', $authMagic); |
||
| 100 | |||
| 101 | $this->io->caution('Execute the installation process. All data is initialized.'); |
||
| 102 | $question = new ConfirmationQuestion('Is it OK?'); |
||
| 103 | if (!$this->io->askQuestion($question)) { |
||
| 104 | // `no`の場合はキャンセルメッセージを出力して終了する |
||
| 105 | $this->setCode(function () { |
||
| 106 | $this->io->success('EC-CUBE installation stopped.'); |
||
| 107 | }); |
||
| 108 | |||
| 109 | return; |
||
| 110 | } |
||
| 111 | |||
| 112 | $envParameters = [ |
||
| 113 | 'APP_ENV' => 'dev', |
||
| 114 | 'APP_DEBUG' => '1', |
||
| 115 | 'DATABASE_URL' => $databaseUrl, |
||
| 116 | 'DATABASE_SERVER_VERSION' => $serverVersion, |
||
| 117 | 'MAILER_URL' => $mailerUrl, |
||
| 118 | 'ECCUBE_AUTH_MAGIC' => $authMagic, |
||
| 119 | 'ECCUBE_ADMIN_ROUTE' => 'admin', |
||
| 120 | 'ECCUBE_TEMPLATE_CODE' => 'default', |
||
| 121 | 'ECCUBE_LOCALE' => 'ja', |
||
| 122 | ]; |
||
| 123 | |||
| 124 | $envDir = $this->container->getParameter('kernel.project_dir'); |
||
| 125 | $envFile = $envDir.'/.env'; |
||
| 126 | $envDistFile = $envDir.'/.env.dist'; |
||
| 127 | |||
| 128 | $env = file_exists($envFile) |
||
| 129 | ? file_get_contents($envFile) |
||
| 130 | : file_get_contents($envDistFile); |
||
| 131 | |||
| 132 | $env = StringUtil::replaceOrAddEnv($env, $envParameters); |
||
| 133 | |||
| 134 | file_put_contents($envFile, $env); |
||
| 135 | } |
||
| 136 | |||
| 232 |