Conditions | 8 |
Paths | 10 |
Total Lines | 54 |
Code Lines | 36 |
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 |
||
75 | public function actionEditProvider(int $providerId = null, ProviderElement $provider = null) |
||
76 | { |
||
77 | // Immediately create a new Provider |
||
78 | if ($providerId === null) { |
||
79 | $request = Craft::$app->getRequest(); |
||
80 | $providerType = $request->getRequiredBodyParam("providerType"); |
||
81 | $provider = Socializer::$app->providers->getProviderByType($providerType); |
||
82 | if ($provider){ |
||
83 | throw new \Exception(Craft::t('enupal-socializer','Provider '.$provider->name.' already exists')); |
||
84 | } |
||
85 | $providerName = Socializer::$app->providers->getClassNameFromNamespace($providerType); |
||
86 | $providerHandle = lcfirst($providerName); |
||
87 | $provider = Socializer::$app->providers->createNewProvider($providerName, $providerHandle, $providerType); |
||
88 | |||
89 | if ($provider->id) { |
||
90 | $url = UrlHelper::cpUrl('enupal-socializer/providers/edit/'.$provider->id); |
||
91 | return $this->redirect($url); |
||
92 | } else { |
||
93 | $errors = $provider->getErrors(); |
||
94 | throw new \Exception(Craft::t('enupal-socializer','Error creating the Provider'.json_encode($errors))); |
||
95 | } |
||
96 | } else { |
||
97 | if ($providerId !== null) { |
||
|
|||
98 | if ($provider === null) { |
||
99 | // Get the provider |
||
100 | $provider = Socializer::$app->providers->getProviderById($providerId); |
||
101 | |||
102 | if (!$provider) { |
||
103 | throw new NotFoundHttpException(Craft::t('enupal-socializer','Provider not found')); |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | if (is_string($provider->fieldMapping)){ |
||
110 | $provider->fieldMapping = json_decode($provider->fieldMapping, true); |
||
111 | } |
||
112 | |||
113 | $variables['providerId'] = $providerId; |
||
114 | $variables['provider'] = $provider; |
||
115 | |||
116 | // Set the "Continue Editing" URL |
||
117 | $variables['continueEditingUrl'] = 'enupal-socializer/providers/edit/{id}'; |
||
118 | $settings = Socializer::$app->settings->getSettings(); |
||
119 | $variables['settings'] = $settings; |
||
120 | $variables['apiDocumentation'] = $this->getApiDocumentation($provider->type); |
||
121 | $variables['callbackUrl'] = Socializer::$app->settings->getCallbackUrl(); |
||
122 | $variables['supportedUserFields'] = Socializer::$app->providers->getUserFieldsAsOptions(); |
||
123 | $variables['userProfileFields'] = Socializer::$app->providers->getUserProfileFieldsAsOptions(); |
||
124 | $variables['fieldMapping'] = $provider->fieldMapping ?? $settings->fieldMapping ?? Socializer::$app->providers->getDefaultFieldMapping(); |
||
125 | $userProfileFields = Socializer::$app->providers->getUserProfileFieldsAsOptions(); |
||
126 | $variables['userProfileFields'] = $userProfileFields; |
||
127 | |||
128 | return $this->renderTemplate('enupal-socializer/providers/_edit', $variables); |
||
129 | } |
||
185 |