Conditions | 2 |
Paths | 2 |
Total Lines | 51 |
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 |
||
120 | public static function handleChangedToken(ConfigEvent $event) |
||
121 | { |
||
122 | Event::off( |
||
123 | Token::class, |
||
124 | Token::EVENT_AFTER_INSERT, |
||
125 | [ |
||
126 | ManageTokenProjectConfig::class, |
||
127 | 'save' |
||
128 | ] |
||
129 | ); |
||
130 | |||
131 | Event::off( |
||
132 | Token::class, |
||
133 | Token::EVENT_AFTER_UPDATE, |
||
134 | [ |
||
135 | ManageTokenProjectConfig::class, |
||
136 | 'save' |
||
137 | ] |
||
138 | ); |
||
139 | |||
140 | // Get the UID that was matched in the config path |
||
141 | $uid = $event->tokenMatches[0]; |
||
142 | |||
143 | if (null === ($token = Token::findOne([ |
||
144 | 'uid' => $uid |
||
145 | ]))) { |
||
146 | $token = new Token(); |
||
147 | } |
||
148 | |||
149 | Craft::configure($token, $event->newValue); |
||
150 | |||
151 | $token->save(); |
||
152 | |||
153 | Event::on( |
||
154 | Token::class, |
||
155 | Token::EVENT_AFTER_INSERT, |
||
156 | [ |
||
157 | ManageTokenProjectConfig::class, |
||
158 | 'save' |
||
159 | ] |
||
160 | ); |
||
161 | |||
162 | Event::on( |
||
163 | Token::class, |
||
164 | Token::EVENT_AFTER_UPDATE, |
||
165 | [ |
||
166 | ManageTokenProjectConfig::class, |
||
167 | 'save' |
||
168 | ] |
||
169 | ); |
||
170 | } |
||
171 | |||
227 |