Conditions | 10 |
Paths | 26 |
Total Lines | 40 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
11 | public function canCreate($member = null, $context = []) |
||
12 | { |
||
13 | if (! $member) { |
||
14 | $member = Security::getCurrentUser(); |
||
15 | } |
||
16 | |||
17 | if ($this->hasMethod('canEditingOwnerObject')) { |
||
|
|||
18 | $obj = $this->canEditingOwnerObject(); |
||
19 | if ($obj instanceof ArrayList) { |
||
20 | $outcome = true; |
||
21 | foreach ($obj as $item) { |
||
22 | if (! $item->canCreate($member, $context)) { |
||
23 | $outcome = false; |
||
24 | |||
25 | break; |
||
26 | } |
||
27 | } |
||
28 | |||
29 | if ($outcome) { |
||
30 | return parent::canCreate($member, $context); |
||
31 | } |
||
32 | |||
33 | return false; |
||
34 | } |
||
35 | |||
36 | return $obj->canCreate($member, $context); |
||
37 | } |
||
38 | |||
39 | $groupCodes = $this->hasMethod('canEditingGroupsCodes') ? $this->canEditingGroupsCodes() : [ |
||
40 | 'CMS_ACCESS_CMSMain', |
||
41 | ]; |
||
42 | $groupCodes = array_merge(['ADMIN'], $groupCodes); |
||
43 | |||
44 | foreach ($groupCodes as $groupCode) { |
||
45 | if (Permission::checkMember($member, $groupCode)) { |
||
46 | return parent::canCreate($member, $context); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | return false; |
||
51 | } |
||
63 |