Conditions | 10 |
Paths | 144 |
Total Lines | 86 |
Code Lines | 61 |
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 declare(strict_types=1); |
||
32 | public function writeConfig(DatabaseConnectionInformation $info, array $shop): void |
||
33 | { |
||
34 | $key = Key::createNewRandomKey(); |
||
35 | $secret = $key->saveToAsciiSafeString(); |
||
36 | |||
37 | $newEnv = []; |
||
38 | |||
39 | $newEnv[] = '###> symfony/lock ###'; |
||
40 | $newEnv[] = '# Choose one of the stores below'; |
||
41 | $newEnv[] = '# postgresql+advisory://db_user:db_password@localhost/db_name'; |
||
42 | $newEnv[] = 'LOCK_DSN=flock'; |
||
43 | $newEnv[] = '###< symfony/lock ###'; |
||
44 | $newEnv[] = ''; |
||
45 | |||
46 | $newEnv[] = '###> symfony/messenger ###'; |
||
47 | $newEnv[] = '# Choose one of the transports below'; |
||
48 | $newEnv[] = '# MESSENGER_TRANSPORT_DSN=doctrine://default'; |
||
49 | $newEnv[] = '# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages'; |
||
50 | $newEnv[] = '# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages'; |
||
51 | $newEnv[] = '###< symfony/messenger ###'; |
||
52 | $newEnv[] = ''; |
||
53 | |||
54 | $newEnv[] = '###> symfony/mailer ###'; |
||
55 | $newEnv[] = 'MAILER_DSN=null://null'; |
||
56 | $newEnv[] = '###< symfony/mailer ###'; |
||
57 | $newEnv[] = ''; |
||
58 | |||
59 | $newEnv[] = '###> shopware/core ###'; |
||
60 | $newEnv[] = 'APP_ENV=prod'; |
||
61 | $newEnv[] = 'APP_SECRET=' . $secret; |
||
62 | $newEnv[] = 'APP_URL=' . $shop['schema'] . '://' . $shop['host'] . $shop['basePath']; |
||
63 | $newEnv[] = 'DATABASE_URL=' . $info->asDsn(); |
||
64 | |||
65 | if (!empty($info->getSslCaPath())) { |
||
66 | $newEnv[] = 'DATABASE_SSL_CA=' . $info->getSslCaPath(); |
||
67 | } |
||
68 | |||
69 | if (!empty($info->getSslCertPath())) { |
||
70 | $newEnv[] = 'DATABASE_SSL_CERT=' . $info->getSslCertPath(); |
||
71 | } |
||
72 | |||
73 | if (!empty($info->getSslCertKeyPath())) { |
||
74 | $newEnv[] = 'DATABASE_SSL_KEY=' . $info->getSslCertKeyPath(); |
||
75 | } |
||
76 | |||
77 | if ($info->getSslDontVerifyServerCert() !== null) { |
||
78 | $newEnv[] = 'DATABASE_SSL_DONT_VERIFY_SERVER_CERT=' . ($info->getSslDontVerifyServerCert() ? '1' : ''); |
||
79 | } |
||
80 | |||
81 | $newEnv[] = 'COMPOSER_HOME=' . $this->projectDir . '/var/cache/composer'; |
||
82 | $newEnv[] = 'INSTANCE_ID=' . $this->idGenerator->getUniqueId(); |
||
83 | $newEnv[] = 'BLUE_GREEN_DEPLOYMENT=' . (int) $shop['blueGreenDeployment']; |
||
84 | $newEnv[] = '###< shopware/core ###'; |
||
85 | $newEnv[] = ''; |
||
86 | |||
87 | $newEnv[] = '###> shopware/elasticsearch ###'; |
||
88 | |||
89 | if (file_exists($this->projectDir . '/symfony.lock')) { |
||
90 | $newEnv[] = 'OPENSEARCH_URL=http://localhost:9200'; |
||
91 | } else { |
||
92 | $newEnv[] = 'SHOPWARE_ES_HOSTS=http://localhost:9200'; |
||
93 | } |
||
94 | |||
95 | $newEnv[] = 'SHOPWARE_ES_ENABLED=0'; |
||
96 | $newEnv[] = 'SHOPWARE_ES_INDEXING_ENABLED=0'; |
||
97 | $newEnv[] = 'SHOPWARE_ES_INDEX_PREFIX=sw'; |
||
98 | $newEnv[] = 'SHOPWARE_ES_THROW_EXCEPTION=1'; |
||
99 | $newEnv[] = '###< shopware/elasticsearch ###'; |
||
100 | $newEnv[] = ''; |
||
101 | |||
102 | $newEnv[] = '###> shopware/storefront ###'; |
||
103 | $newEnv[] = 'SHOPWARE_HTTP_CACHE_ENABLED=1'; |
||
104 | $newEnv[] = 'SHOPWARE_HTTP_DEFAULT_TTL=7200'; |
||
105 | $newEnv[] = '###< shopware/storefront ###'; |
||
106 | $newEnv[] = ''; |
||
107 | |||
108 | file_put_contents($this->projectDir . '/.env', implode("\n", $newEnv)); |
||
109 | |||
110 | $htaccessPath = $this->projectDir . '/public/.htaccess'; |
||
111 | |||
112 | if (file_exists($htaccessPath . '.dist') && !file_exists($htaccessPath)) { |
||
113 | $perms = fileperms($htaccessPath . '.dist'); |
||
114 | copy($htaccessPath . '.dist', $htaccessPath); |
||
115 | |||
116 | if ($perms) { |
||
117 | chmod($htaccessPath, $perms | 0644); |
||
118 | } |
||
122 |