Conditions | 10 |
Paths | 20 |
Total Lines | 89 |
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 |
||
25 | public function initCreateMeeting(array $parameters) |
||
26 | { |
||
27 | $request = Fluent($parameters); |
||
28 | $meetingParams = new CreateMeetingParameters($request->meetingID, $request->meetingName); |
||
29 | $meetingParams->setModeratorPassword($request->get('moderatorPW', Str::random(config('bigbluebutton.create.passwordLength', 8)))); |
||
30 | $meetingParams->setAttendeePassword($request->get('attendeePW', Str::random(config('bigbluebutton.create.passwordLength', 8)))); |
||
31 | $meetingParams->setDuration($request->get('duration', config('bigbluebutton.create.duration', null))); |
||
32 | $meetingParams->setRecord($request->get('record', config('bigbluebutton.create.record', false))); |
||
33 | $meetingParams->setMaxParticipants($request->get('maxParticipants', config('bigbluebutton.create.maxParticipants', null))); |
||
34 | $meetingParams->setLogoutUrl($request->get('logoutUrl', config('bigbluebutton.create.logoutUrl', null))); |
||
35 | $meetingParams->setWelcomeMessage( |
||
36 | $request->get('welcomeMessage', config('bigbluebutton.create.welcomeMessage', null)) |
||
37 | ); |
||
38 | $meetingParams->setDialNumber( |
||
39 | $request->get('dialNumber', config('bigbluebutton.create.dialNumber', null)) |
||
40 | ); |
||
41 | $meetingParams->setBreakout( |
||
42 | $request->get('isBreakout', config('bigbluebutton.create.isBreakout', false)) |
||
43 | ); |
||
44 | $meetingParams->setModeratorOnlyMessage( |
||
45 | $request->get('moderatorOnlyMessage', config('bigbluebutton.create.moderatorOnlyMessage', null)) |
||
46 | ); |
||
47 | $meetingParams->setAutoStartRecording( |
||
48 | $request->get('autoStartRecording', config('bigbluebutton.create.autoStartRecording', false)) |
||
49 | ); |
||
50 | $meetingParams->setAllowStartStopRecording( |
||
51 | $request->get('allowStartStopRecording', config('bigbluebutton.create.allowStartStopRecording', true)) |
||
52 | ); |
||
53 | $meetingParams->setWebcamsOnlyForModerator( |
||
54 | $request->get('webcamsOnlyForModerator', config('bigbluebutton.create.webcamsOnlyForModerator', false)) |
||
55 | ); |
||
56 | $meetingParams->setLogo( |
||
57 | $request->get('logo', config('bigbluebutton.create.logo', null)) |
||
58 | ); |
||
59 | $meetingParams->setCopyright( |
||
60 | $request->get('copyright', config('bigbluebutton.create.copyright', null)) |
||
61 | ); |
||
62 | $meetingParams->setMuteOnStart( |
||
63 | $request->get('muteOnStart', config('bigbluebutton.create.muteOnStart', false)) |
||
64 | ); |
||
65 | $meetingParams->setLockSettingsDisableCam( |
||
66 | $request->get('lockSettingsDisableCam', config('bigbluebutton.create.lockSettingsDisableCam', false)) |
||
67 | ); |
||
68 | $meetingParams->setLockSettingsDisableMic( |
||
69 | $request->get('lockSettingsDisableMic', config('bigbluebutton.create.lockSettingsDisableMic', false)) |
||
70 | ); |
||
71 | $meetingParams->setLockSettingsDisablePrivateChat( |
||
72 | $request->get('lockSettingsDisablePrivateChat', config('bigbluebutton.create.lockSettingsDisablePrivateChat', false)) |
||
73 | ); |
||
74 | $meetingParams->setLockSettingsDisablePublicChat( |
||
75 | $request->get('lockSettingsDisablePublicChat', config('bigbluebutton.create.lockSettingsDisablePublicChat', false)) |
||
76 | ); |
||
77 | $meetingParams->setLockSettingsDisableNote( |
||
78 | $request->get('lockSettingsDisableNote', config('bigbluebutton.create.lockSettingsDisableNote', false)) |
||
79 | ); |
||
80 | $meetingParams->setLockSettingsLockedLayout( |
||
81 | $request->get('lockSettingsLockedLayout', config('bigbluebutton.create.lockSettingsLockedLayout', false)) |
||
82 | ); |
||
83 | $meetingParams->setLockSettingsLockOnJoin( |
||
84 | $request->get('lockSettingsLockOnJoin', config('bigbluebutton.create.lockSettingsLockOnJoin', false)) |
||
85 | ); |
||
86 | $meetingParams->setLockSettingsLockOnJoinConfigurable( |
||
87 | $request->get('lockSettingsLockOnJoinConfigurable', config('bigbluebutton.create.lockSettingsLockOnJoinConfigurable', false)) |
||
88 | ); |
||
89 | |||
90 | if (!is_null($request->get('endCallbackUrl', null))) { |
||
91 | $meetingParams->setEndCallbackUrl($request->get('endCallbackUrl', null)); |
||
92 | } |
||
93 | |||
94 | $meetingParams->setFreeJoin($request->get('freeJoin', false)); |
||
95 | |||
96 | $presentation = (array) $request->get('presentation', null); |
||
97 | foreach ($presentation as $item) { |
||
98 | if (isset($item['fileName']) && !empty($item['fileName'])) { |
||
99 | if (isset($item['link']) && !empty($item['link'])) { |
||
100 | $meetingParams->addPresentation(trim($item['link']),null,trim($item['fileName'])); |
||
101 | } elseif (isset($item['content']) && !empty($item['content'])) { |
||
102 | $meetingParams->addPresentation(trim($item['fileName']),trim($item['content']),null); |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | $meta = (array) $request->get('meta', null); |
||
108 | foreach ($meta as $key => $value) { |
||
109 | $meetingParams->addMeta(trim($key), trim($value)); |
||
110 | } |
||
111 | |||
112 | return $meetingParams; |
||
113 | } |
||
114 | |||
260 |
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.