Conditions | 6 |
Paths | 5 |
Total Lines | 71 |
Lines | 21 |
Ratio | 29.58 % |
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 |
||
83 | protected function triggerChangeHooks(IStorageConfig $oldStorage, IStorageConfig $newStorage) { |
||
84 | // if mount point changed, it's like a deletion + creation |
||
85 | View Code Duplication | if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { |
|
|
|||
86 | $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); |
||
87 | $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
||
88 | return; |
||
89 | } |
||
90 | |||
91 | $userAdditions = \array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
||
92 | $userDeletions = \array_diff($oldStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
||
93 | $groupAdditions = \array_diff($newStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
||
94 | $groupDeletions = \array_diff($oldStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
||
95 | |||
96 | // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
||
97 | // if no applicable were set, raise a signal for "all" |
||
98 | $oldApplicableUsers = $oldStorage->getApplicableUsers(); |
||
99 | $oldApplicableGroups = $oldStorage->getApplicableGroups(); |
||
100 | View Code Duplication | if (empty($oldApplicableUsers) && empty($oldApplicableGroups)) { |
|
101 | $this->triggerApplicableHooks( |
||
102 | Filesystem::signal_delete_mount, |
||
103 | $oldStorage->getMountPoint(), |
||
104 | IStorageConfig::MOUNT_TYPE_USER, |
||
105 | ['all'] |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | // trigger delete for removed users |
||
110 | $this->triggerApplicableHooks( |
||
111 | Filesystem::signal_delete_mount, |
||
112 | $oldStorage->getMountPoint(), |
||
113 | IStorageConfig::MOUNT_TYPE_USER, |
||
114 | $userDeletions |
||
115 | ); |
||
116 | |||
117 | // trigger delete for removed groups |
||
118 | $this->triggerApplicableHooks( |
||
119 | Filesystem::signal_delete_mount, |
||
120 | $oldStorage->getMountPoint(), |
||
121 | IStorageConfig::MOUNT_TYPE_GROUP, |
||
122 | $groupDeletions |
||
123 | ); |
||
124 | |||
125 | // and now add the new users |
||
126 | $this->triggerApplicableHooks( |
||
127 | Filesystem::signal_create_mount, |
||
128 | $newStorage->getMountPoint(), |
||
129 | IStorageConfig::MOUNT_TYPE_USER, |
||
130 | $userAdditions |
||
131 | ); |
||
132 | |||
133 | // and now add the new groups |
||
134 | $this->triggerApplicableHooks( |
||
135 | Filesystem::signal_create_mount, |
||
136 | $newStorage->getMountPoint(), |
||
137 | IStorageConfig::MOUNT_TYPE_GROUP, |
||
138 | $groupAdditions |
||
139 | ); |
||
140 | |||
141 | // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
||
142 | // if no applicable, raise a signal for "all" |
||
143 | $newApplicableUsers = $newStorage->getApplicableUsers(); |
||
144 | $newApplicableGroups = $newStorage->getApplicableGroups(); |
||
145 | View Code Duplication | if (empty($newApplicableUsers) && empty($newApplicableGroups)) { |
|
146 | $this->triggerApplicableHooks( |
||
147 | Filesystem::signal_create_mount, |
||
148 | $newStorage->getMountPoint(), |
||
149 | IStorageConfig::MOUNT_TYPE_USER, |
||
150 | ['all'] |
||
151 | ); |
||
152 | } |
||
153 | } |
||
154 | |||
219 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.