Conditions | 6 |
Paths | 9 |
Total Lines | 78 |
Code Lines | 40 |
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 |
||
22 | public static function install($installedAddon) |
||
23 | { |
||
24 | /** @var array $providerInstaller An array with the models of all providers */ |
||
25 | $providerInstaller = self::getProviderInstaller(); |
||
26 | // check requirements of Gateway |
||
27 | if (!self::meetsRequirements($error)) { |
||
28 | throw new XenForo_Exception($error); |
||
29 | } |
||
30 | |||
31 | // Get installed add-on version |
||
32 | /** @var int $oldAddonVersion internal version number of installed addon version */ |
||
33 | $oldAddonVersion = is_array($installedAddon) ? $installedAddon['version_id'] : 0; |
||
34 | |||
35 | // Not installed |
||
36 | if ($oldAddonVersion == 0) { |
||
37 | // add tfa providers to database |
||
38 | foreach ($providerInstaller as $provider) { |
||
39 | $provider->add(); |
||
40 | } |
||
41 | |||
42 | // add permissions |
||
43 | /** @var ThreemaGateway_Installer_Permissions $permissionsInstaller */ |
||
44 | $permissionsInstaller = new ThreemaGateway_Installer_Permissions; |
||
45 | // allow everything for registered users by default |
||
46 | $permissionsInstaller->addForUserGroup(2, 'use', 'allow'); |
||
47 | $permissionsInstaller->addForUserGroup(2, 'send', 'allow'); |
||
48 | $permissionsInstaller->addForUserGroup(2, 'receive', 'allow'); |
||
49 | $permissionsInstaller->addForUserGroup(2, 'fetch', 'allow'); |
||
50 | $permissionsInstaller->addForUserGroup(2, 'lookup', 'allow'); |
||
51 | $permissionsInstaller->addForUserGroup(2, 'tfa', 'allow'); |
||
52 | |||
53 | // allow registered users some basic (uncritical) block actions |
||
54 | $permissionsInstaller->addForUserGroup(2, 'blockedNotification', 'allow'); |
||
55 | $permissionsInstaller->addForUserGroup(2, 'blockTfaMode', 'allow'); |
||
56 | |||
57 | // allow all block actions for mods (& thus also admins) |
||
58 | $permissionsInstaller->addForUserGroup(4, 'blockedNotification', 'allow'); |
||
59 | $permissionsInstaller->addForUserGroup(4, 'blockTfaMode', 'allow'); |
||
60 | $permissionsInstaller->addForUserGroup(4, 'blockUser', 'allow'); // not possible as mods/admins cannot be blocked, but we allow it :) |
||
61 | $permissionsInstaller->addForUserGroup(4, 'blockIp', 'allow'); |
||
62 | |||
63 | // create public key store |
||
64 | /** @var ThreemaGateway_Installer_Keystore $keystoreInstaller */ |
||
65 | $keystoreInstaller = new ThreemaGateway_Installer_Keystore; |
||
66 | $keystoreInstaller->create(); |
||
67 | |||
68 | // create custom user field |
||
69 | /** @var XenForo_DataWriter $userFieldWriter */ |
||
70 | $userFieldWriter = XenForo_DataWriter::create('XenForo_DataWriter_UserField'); |
||
71 | $userFieldWriter->set('field_id', 'threemaid'); |
||
72 | $userFieldWriter->set('display_group', 'contact'); |
||
73 | $userFieldWriter->set('display_order', 120); |
||
74 | $userFieldWriter->set('field_type', 'textbox'); |
||
75 | $userFieldWriter->set('match_type', 'callback'); |
||
76 | $userFieldWriter->set('match_callback_class', 'ThreemaGateway_Helper_UserField'); |
||
77 | $userFieldWriter->set('match_callback_method', 'verifyThreemaId'); |
||
78 | $userFieldWriter->set('max_length', 8); |
||
79 | $userFieldWriter->save(); |
||
80 | |||
81 | // create tables for messages |
||
82 | /** @var ThreemaGateway_Installer_MessagesDb $messageDbInstaller */ |
||
83 | $messageDbInstaller = new ThreemaGateway_Installer_MessagesDb; |
||
84 | $messageDbInstaller->create(); |
||
85 | |||
86 | // create tfa tables |
||
87 | /** @var ThreemaGateway_Installer_TfaPendingConfirmMsgs $pendReqInstaller */ |
||
88 | $pendReqInstaller = new ThreemaGateway_Installer_TfaPendingConfirmMsgs; |
||
89 | $pendReqInstaller->create(); |
||
90 | } |
||
91 | |||
92 | // introduced in v1.00.00 70 (stable) |
||
|
|||
93 | if ($oldAddonVersion < 1000070) { |
||
94 | // add throttle table |
||
95 | /** @var ThreemaGateway_Installer_ActionThrottle $throttleInstaller */ |
||
96 | $throttleInstaller = new ThreemaGateway_Installer_ActionThrottle; |
||
97 | $throttleInstaller->create(); |
||
98 | } |
||
99 | } |
||
100 | |||
221 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.