Conditions | 10 |
Paths | 20 |
Total Lines | 90 |
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 |
||
30 | public function initCreateMeeting(array $parameters) |
||
31 | { |
||
32 | $request = Fluent($parameters); |
||
33 | $meetingParams = new CreateMeetingParameters($request->meetingID, $request->meetingName); |
||
34 | $meetingParams->setModeratorPassword($request->get('moderatorPW', Str::random(config('bigbluebutton.create.passwordLength', 8)))); |
||
35 | $meetingParams->setAttendeePassword($request->get('attendeePW', Str::random(config('bigbluebutton.create.passwordLength', 8)))); |
||
36 | $meetingParams->setDuration($request->get('duration', config('bigbluebutton.create.duration', 0))); |
||
37 | $meetingParams->setRecord($request->get('record', config('bigbluebutton.create.record', false))); |
||
38 | $meetingParams->setMaxParticipants($request->get('maxParticipants', config('bigbluebutton.create.maxParticipants', 0))); |
||
39 | $meetingParams->setLogoutUrl($request->get('logoutUrl', config('bigbluebutton.create.logoutUrl', null))); |
||
40 | $meetingParams->setWelcomeMessage( |
||
41 | $request->get('welcomeMessage', config('bigbluebutton.create.welcomeMessage', null)) |
||
42 | ); |
||
43 | $meetingParams->setDialNumber( |
||
44 | $request->get('dialNumber', config('bigbluebutton.create.dialNumber', null)) |
||
45 | ); |
||
46 | $meetingParams->setBreakout( |
||
47 | $request->get('isBreakout', config('bigbluebutton.create.isBreakout', false)) |
||
48 | ); |
||
49 | $meetingParams->setModeratorOnlyMessage( |
||
50 | $request->get('moderatorOnlyMessage', config('bigbluebutton.create.moderatorOnlyMessage', null)) |
||
51 | ); |
||
52 | $meetingParams->setAutoStartRecording( |
||
53 | $request->get('autoStartRecording', config('bigbluebutton.create.autoStartRecording', false)) |
||
54 | ); |
||
55 | $meetingParams->setAllowStartStopRecording( |
||
56 | $request->get('allowStartStopRecording', config('bigbluebutton.create.allowStartStopRecording', true)) |
||
57 | ); |
||
58 | $meetingParams->setWebcamsOnlyForModerator( |
||
59 | $request->get('webcamsOnlyForModerator', config('bigbluebutton.create.webcamsOnlyForModerator', false)) |
||
60 | ); |
||
61 | $meetingParams->setLogo( |
||
62 | $request->get('logo', config('bigbluebutton.create.logo', null)) |
||
63 | ); |
||
64 | $meetingParams->setCopyright( |
||
65 | $request->get('copyright', config('bigbluebutton.create.copyright', null)) |
||
66 | ); |
||
67 | $meetingParams->setMuteOnStart( |
||
68 | $request->get('muteOnStart', config('bigbluebutton.create.muteOnStart', false)) |
||
69 | ); |
||
70 | |||
71 | $meetingParams->setLockSettingsDisableCam( |
||
72 | $request->get('lockSettingsDisableCam', config('bigbluebutton.create.lockSettingsDisableCam', false)) |
||
73 | ); |
||
74 | $meetingParams->setLockSettingsDisableMic( |
||
75 | $request->get('lockSettingsDisableMic', config('bigbluebutton.create.lockSettingsDisableMic', false)) |
||
76 | ); |
||
77 | $meetingParams->setLockSettingsDisablePrivateChat( |
||
78 | $request->get('lockSettingsDisablePrivateChat', config('bigbluebutton.create.lockSettingsDisablePrivateChat', false)) |
||
79 | ); |
||
80 | $meetingParams->setLockSettingsDisablePublicChat( |
||
81 | $request->get('lockSettingsDisablePublicChat', config('bigbluebutton.create.lockSettingsDisablePublicChat', false)) |
||
82 | ); |
||
83 | $meetingParams->setLockSettingsDisableNote( |
||
84 | $request->get('lockSettingsDisableNote', config('bigbluebutton.create.lockSettingsDisableNote', false)) |
||
85 | ); |
||
86 | $meetingParams->setLockSettingsLockedLayout( |
||
87 | $request->get('lockSettingsLockedLayout', config('bigbluebutton.create.lockSettingsLockedLayout', false)) |
||
88 | ); |
||
89 | $meetingParams->setLockSettingsLockOnJoin( |
||
90 | $request->get('lockSettingsLockOnJoin', config('bigbluebutton.create.lockSettingsLockOnJoin', false)) |
||
91 | ); |
||
92 | $meetingParams->setLockSettingsLockOnJoinConfigurable( |
||
93 | $request->get('lockSettingsLockOnJoinConfigurable', config('bigbluebutton.create.lockSettingsLockOnJoinConfigurable', false)) |
||
94 | ); |
||
95 | |||
96 | if (!is_null($request->get('endCallbackUrl', null))) { |
||
97 | $meetingParams->setEndCallbackUrl($request->get('endCallbackUrl', null)); |
||
98 | } |
||
99 | |||
100 | $meetingParams->setFreeJoin($request->get('freeJoin', false)); |
||
101 | |||
102 | $presentation = (array)$request->get('presentation', null); |
||
103 | foreach ($presentation as $item) { |
||
104 | if (isset($item['fileName']) && !empty($item['fileName'])) { |
||
105 | if (isset($item['link']) && !empty($item['link'])) { |
||
106 | $meetingParams->addPresentation(trim($item['link']), null, trim($item['fileName'])); |
||
107 | } elseif (isset($item['content']) && !empty($item['content'])) { |
||
108 | $meetingParams->addPresentation(trim($item['fileName']), trim($item['content']), null); |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | |||
113 | $meta = (array)$request->get('meta', null); |
||
114 | foreach ($meta as $key => $value) { |
||
115 | $meetingParams->addMeta(trim($key), trim($value)); |
||
116 | } |
||
117 | |||
118 | return $meetingParams; |
||
119 | } |
||
120 | |||
321 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.