| Conditions | 11 |
| Paths | 384 |
| Total Lines | 105 |
| 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 | // 以下環境変数に規定済の設定値があれば利用する |
||
| 102 | // APP_ENV |
||
| 103 | $appEnv = env('APP_ENV', 'dev'); |
||
| 104 | // .envが存在しない状態では規定値'install'となっているため、devに更新する |
||
| 105 | if ($appEnv === 'install') { |
||
| 106 | $appEnv = 'dev'; |
||
| 107 | } |
||
| 108 | |||
| 109 | // APP_DEBUG |
||
| 110 | $appDebug = env('APP_DEBUG','1'); |
||
| 111 | |||
| 112 | // ECCUBE_ADMIN_ROUTE |
||
| 113 | $adminRoute = $this->container->getParameter('eccube_admin_route'); |
||
| 114 | if (empty($adminRoute)) { |
||
| 115 | $adminRoute = 'admin'; |
||
| 116 | } |
||
| 117 | |||
| 118 | // ECCUBE_TEMPLATE_CODE |
||
| 119 | $templateCode = $this->container->getParameter('eccube_theme_code'); |
||
| 120 | if (empty($templateCode)) { |
||
| 121 | $templateCode = 'default'; |
||
| 122 | } |
||
| 123 | |||
| 124 | // ECCUBE_LOCALE |
||
| 125 | $locale = $this->container->getParameter('locale'); |
||
| 126 | if (empty($locale)) { |
||
| 127 | $locale = 'ja'; |
||
| 128 | } |
||
| 129 | |||
| 130 | $this->io->caution('Execute the installation process. All data is initialized.'); |
||
| 131 | $question = new ConfirmationQuestion('Is it OK?'); |
||
| 132 | if (!$this->io->askQuestion($question)) { |
||
| 133 | // `no`の場合はキャンセルメッセージを出力して終了する |
||
| 134 | $this->setCode(function () { |
||
| 135 | $this->io->success('EC-CUBE installation stopped.'); |
||
| 136 | }); |
||
| 137 | |||
| 138 | return; |
||
| 139 | } |
||
| 140 | |||
| 141 | $envParameters = [ |
||
| 142 | 'APP_ENV' => $appEnv, |
||
| 143 | 'APP_DEBUG' => $appDebug, |
||
| 144 | 'DATABASE_URL' => $databaseUrl, |
||
| 145 | 'DATABASE_SERVER_VERSION' => $serverVersion, |
||
| 146 | 'MAILER_URL' => $mailerUrl, |
||
| 147 | 'ECCUBE_AUTH_MAGIC' => $authMagic, |
||
| 148 | 'ECCUBE_ADMIN_ROUTE' => $adminRoute, |
||
| 149 | 'ECCUBE_TEMPLATE_CODE' => $templateCode, |
||
| 150 | 'ECCUBE_LOCALE' => $locale, |
||
| 151 | ]; |
||
| 152 | |||
| 153 | $envDir = $this->container->getParameter('kernel.project_dir'); |
||
| 154 | $envFile = $envDir.'/.env'; |
||
| 155 | $envDistFile = $envDir.'/.env.dist'; |
||
| 156 | |||
| 157 | $env = file_exists($envFile) |
||
| 158 | ? file_get_contents($envFile) |
||
| 159 | : file_get_contents($envDistFile); |
||
| 160 | |||
| 161 | $env = StringUtil::replaceOrAddEnv($env, $envParameters); |
||
| 162 | |||
| 163 | file_put_contents($envFile, $env); |
||
| 164 | } |
||
| 165 | |||
| 261 |