Complex classes like AbstractProvider often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractProvider, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | abstract class AbstractProvider extends ActiveRecord implements ProviderInterface |
||
24 | { |
||
25 | |||
26 | use traits\EntityDescriptor, traits\KeyChain, traits\MapUser, Ember; |
||
27 | |||
28 | const METADATA_HASH_ALGORITHM = 'sha256'; |
||
29 | const DEFAULT_GROUPS_ATTRIBUTE_NAME = 'groups'; |
||
30 | |||
31 | protected $metadataModel; |
||
32 | protected $cachedKeychain; |
||
33 | |||
34 | /** |
||
35 | * This method helps initiate the login process for a remote provider. |
||
36 | * When using this method, say your craft site is the SP. This method will be helpful |
||
37 | * on the IDP provider record. Going to this login path will |
||
38 | * initiate the login process for this IDP. Returns null when you getLoginPath for the |
||
39 | * local provider (the current craft site). |
||
40 | * |
||
41 | * @return string|null |
||
42 | */ |
||
43 | abstract public function getLoginPath(); |
||
44 | |||
45 | /** |
||
46 | * Similar to getLoginPath(), this method initiates logout with the intended remote |
||
47 | * provider. |
||
48 | * |
||
49 | * @return string|null |
||
50 | */ |
||
51 | abstract public function getLogoutPath(); |
||
52 | |||
53 | abstract protected function getDefaultSettings():AbstractSettings; |
||
54 | |||
55 | public function getLoginRequestEndpoint(AbstractSettings $settings = null) |
||
64 | |||
65 | public function getLoginEndpoint(AbstractSettings $settings = null) |
||
74 | |||
75 | public function getLogoutRequestEndpoint(AbstractSettings $settings = null) |
||
84 | |||
85 | public function getLogoutEndpoint(AbstractSettings $settings = null) |
||
94 | |||
95 | /** |
||
96 | * @inheritDoc |
||
97 | */ |
||
98 | public function loadDefaultValues($skipIfSet = true) |
||
109 | |||
110 | /** |
||
111 | * @throws \Exception |
||
112 | */ |
||
113 | public function generateUid() |
||
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | */ |
||
123 | public function beforeSave($insert) |
||
151 | |||
152 | /** |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getEntityId() |
||
160 | |||
161 | /** |
||
162 | * @return EntityDescriptor |
||
163 | */ |
||
164 | public function getMetadataModel() |
||
175 | |||
176 | /** |
||
177 | * @param EntityDescriptor $descriptor |
||
178 | * @return $this |
||
179 | */ |
||
180 | public function setMetadataModel(EntityDescriptor $descriptor) |
||
185 | |||
186 | /** |
||
187 | * @return bool |
||
188 | */ |
||
189 | public function isIdentityProvider() |
||
193 | |||
194 | /** |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function isServiceProvider() |
||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getType() |
||
209 | |||
210 | /** |
||
211 | * @return ActiveQuery |
||
212 | */ |
||
213 | public function getLink() |
||
219 | |||
220 | /** |
||
221 | * @return ActiveQuery |
||
222 | */ |
||
223 | public function getKeychain() |
||
231 | |||
232 | /** |
||
233 | * @param KeyChainRecord $keyChain |
||
234 | * @return AbstractProvider |
||
235 | */ |
||
236 | public function setKeychain(KeyChainRecord $keyChain) |
||
241 | |||
242 | /** |
||
243 | * |
||
244 | */ |
||
245 | public function setSite(Site $site) |
||
250 | |||
251 | /** |
||
252 | * Returns the provider's site. |
||
253 | * |
||
254 | * @return ActiveQueryInterface The relational query object. |
||
255 | */ |
||
256 | public function getSite(): ActiveQueryInterface |
||
260 | |||
261 | /** |
||
262 | * @return \craft\models\Site|null |
||
263 | */ |
||
264 | public function getSiteModel() |
||
274 | |||
275 | /** |
||
276 | * @param array $mapping |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function setMapping(array $mapping) |
||
285 | |||
286 | /** |
||
287 | * @return array |
||
288 | */ |
||
289 | public function getMapping() |
||
298 | |||
299 | public function setMetadataOptions(MetadataOptions $metadataOptions) |
||
305 | |||
306 | public function getMetadataOptions(): MetadataOptions |
||
315 | |||
316 | /** |
||
317 | * @param GroupOptions $groupOptions |
||
318 | * @return $this |
||
319 | */ |
||
320 | public function setGroupOptions(GroupOptions $groupOptions) |
||
326 | |||
327 | public function getGroupOptions(): GroupOptions |
||
336 | |||
337 | /** |
||
338 | * @return bool |
||
339 | */ |
||
340 | public function hasMapping() |
||
344 | |||
345 | /** |
||
346 | * @return bool |
||
347 | */ |
||
348 | public function hasGroupOptions(): bool |
||
352 | |||
353 | /** |
||
354 | * @return bool |
||
355 | */ |
||
356 | public function hasMetadataOptions(): bool |
||
360 | |||
361 | /** |
||
362 | * @param string $property |
||
363 | * @return bool |
||
364 | */ |
||
365 | protected function hasJsonProperty(string $property) |
||
377 | } |
||
378 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.