| Conditions | 12 |
| Paths | 42 |
| Total Lines | 64 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 161 | public function getEnvironmentMessage() |
||
| 162 | { |
||
| 163 | $result = ''; |
||
| 164 | /** @var Settings $settings */ |
||
| 165 | $settings = Seomatic::$plugin->getSettings(); |
||
| 166 | $settingsEnv = $settings->environment; |
||
| 167 | $settingsEnv = Craft::parseEnv($settingsEnv); |
||
| 168 | $env = Seomatic::$environment; |
||
| 169 | $settingsUrl = UrlHelper::cpUrl('seomatic/plugin'); |
||
| 170 | $general = Craft::$app->getConfig()->getGeneral(); |
||
| 171 | if (!$general->allowAdminChanges) { |
||
| 172 | $settingsUrl = ''; |
||
| 173 | } |
||
| 174 | // If they've manually overridden the environment, just return it |
||
| 175 | if (EnvironmentHelper::environmentOverriddenByConfig()) { |
||
| 176 | return Craft::t('seomatic', 'This is overridden by the `config/seomatic.php` config setting', |
||
| 177 | [] |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | // If they have manually set the environment, just return it |
||
| 181 | if (Seomatic::$settings->manuallySetEnvironment) { |
||
| 182 | return Craft::t('seomatic', 'This is set manually by the "Manually Set SEOmatic Environment" plugin setting', |
||
| 183 | [] |
||
| 184 | ); |
||
| 185 | } |
||
| 186 | // If devMode is on, always force the environment to be 'local' |
||
| 187 | if (Seomatic::$devMode) { |
||
| 188 | return Craft::t('seomatic', 'The `{settingsEnv}` [SEOmatic Environment]({settingsUrl}) setting has been overriden to `{env}`, because the `devMode` config setting is enabled. Tracking scripts are disabled, and the `robots` tag is set to `none` to prevent search engine indexing.', |
||
| 189 | ['env' => $env, 'settingsEnv' => $settingsEnv, 'settingsUrl' => $settingsUrl] |
||
| 190 | ); |
||
| 191 | } |
||
| 192 | // This can change depending on the user settings |
||
| 193 | /** @phpstan-ignore-next-line */ |
||
| 194 | if (Seomatic::$settings->manuallySetEnvironment) { |
||
| 195 | $envVar = $settingsEnv; |
||
| 196 | } else { |
||
| 197 | // Try to also check the `ENVIRONMENT` env var |
||
| 198 | $envVar = App::env('ENVIRONMENT'); |
||
| 199 | $envVar = $envVar ?: App::env('CRAFT_ENVIRONMENT'); |
||
| 200 | } |
||
| 201 | if (!empty($envVar)) { |
||
| 202 | $env = EnvironmentHelper::determineEnvironment(); |
||
| 203 | switch ($env) { |
||
| 204 | case EnvironmentHelper::SEOMATIC_DEV_ENV: |
||
| 205 | $additionalMessage = 'Tracking scripts are disabled, and the `robots` tag is set to `none` to prevent search engine indexing.'; |
||
| 206 | break; |
||
| 207 | case EnvironmentHelper::SEOMATIC_STAGING_ENV: |
||
| 208 | $additionalMessage = 'The `robots` tag is set to `none` to prevent search engine indexing.'; |
||
| 209 | break; |
||
| 210 | case EnvironmentHelper::SEOMATIC_PRODUCTION_ENV: |
||
| 211 | $additionalMessage = ''; |
||
| 212 | break; |
||
| 213 | default: |
||
| 214 | $additionalMessage = ''; |
||
| 215 | break; |
||
| 216 | } |
||
| 217 | if ($settings->environment !== $env) { |
||
| 218 | return Craft::t('seomatic', 'The `{settingsEnv}` [SEOmatic Environment]({settingsUrl}) setting has been overriden to `{env}`, because the `.env` setting `ENVIRONMENT` is set to `{envVar}`. {additionalMessage}', |
||
| 219 | ['env' => $env, 'settingsEnv' => $settingsEnv, 'settingsUrl' => $settingsUrl, 'envVar' => $envVar, 'additionalMessage' => $additionalMessage] |
||
| 220 | ); |
||
| 221 | } |
||
| 222 | } |
||
| 223 | |||
| 224 | return $result; |
||
| 225 | } |
||
| 227 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.