Conditions | 11 |
Paths | 528 |
Total Lines | 87 |
Code Lines | 63 |
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 |
||
90 | public function modifyAction($id = ''): void |
||
91 | { |
||
92 | $timeFrame = OutWorkTimes::findFirstById($id); |
||
93 | if ($timeFrame === null) { |
||
94 | $timeFrame = new OutWorkTimes(); |
||
95 | } |
||
96 | $forwardingExtensions = []; |
||
97 | $forwardingExtensions[""] = $this->translation->_("ex_SelectNumber"); |
||
98 | $parameters = [ |
||
99 | 'conditions' => 'number = :extension:', |
||
100 | 'bind' => [ |
||
101 | 'extension' => $timeFrame->extension, |
||
102 | ], |
||
103 | ]; |
||
104 | $extensions = Extensions::find($parameters); |
||
105 | foreach ($extensions as $record) { |
||
106 | $forwardingExtensions[$record->number] = $record->getRepresent(); |
||
107 | } |
||
108 | $audioMessages = []; |
||
109 | $audioMessages[""] = $this->translation->_("sf_SelectAudioFile"); |
||
110 | $soundFiles = SoundFiles::find('category="custom"'); |
||
111 | foreach ($soundFiles as $record) { |
||
112 | $audioMessages[$record->id] = $record->name; |
||
113 | } |
||
114 | |||
115 | $availableActions = [ |
||
116 | 'playmessage' => $this->translation->_('tf_SelectActionPlayMessage'), |
||
117 | 'extension' => $this->translation->_('tf_SelectActionRedirectToExtension'), |
||
118 | ]; |
||
119 | |||
120 | $weekDays = ['-1' => '-']; |
||
121 | for ($i = "1"; $i <= 7; $i++) { |
||
122 | $weekDays[$i] = $this->translation->_(date('D', strtotime("Sunday +{$i} days"))); |
||
123 | } |
||
124 | |||
125 | $form = new TimeFrameEditForm( |
||
126 | $timeFrame, [ |
||
127 | 'extensions' => $forwardingExtensions, |
||
128 | 'audio-message' => $audioMessages, |
||
129 | 'available-actions' => $availableActions, |
||
130 | 'week-days' => $weekDays, |
||
131 | ] |
||
132 | ); |
||
133 | $this->view->form = $form; |
||
134 | $this->view->represent = $timeFrame->getRepresent(); |
||
135 | |||
136 | // Получим список ссылок на разрещенные правила маршутизации в этой группе |
||
137 | $parameters = [ |
||
138 | 'columns' => 'routId AS rule_id', |
||
139 | 'conditions' => 'timeConditionId=:timeConditionId:', |
||
140 | 'bind' => [ |
||
141 | 'timeConditionId' => $id, |
||
142 | ], |
||
143 | ]; |
||
144 | $allowedRules = OutWorkTimesRouts::find($parameters)->toArray(); |
||
145 | $allowedRulesIds = array_column($allowedRules, 'rule_id'); |
||
146 | |||
147 | // Получим список правил маршрутизации |
||
148 | $rules = IncomingRoutingTable::find(['order' => 'priority', 'conditions' => 'id>1']); |
||
149 | $routingTable = []; |
||
150 | foreach ($rules as $rule) { |
||
151 | $provider = $rule->Providers; |
||
152 | if ($provider) { |
||
153 | $modelType = ucfirst($provider->type); |
||
154 | $provByType = $provider->$modelType; |
||
155 | } else { |
||
156 | $provByType = new SIP(); |
||
157 | } |
||
158 | $extension = $rule->Extensions; |
||
159 | $values = [ |
||
160 | 'id' => $rule->id, |
||
161 | 'rulename' => $rule->rulename, |
||
162 | 'priority' => $rule->priority, |
||
163 | 'number' => $rule->number, |
||
164 | 'timeout' => $rule->timeout, |
||
165 | 'provider' => $rule->Providers ? $rule->Providers->getRepresent() : '', |
||
166 | 'provider-uniqid' => $rule->Providers ? $rule->Providers->uniqid : 'none', |
||
167 | 'disabled' => $provByType->disabled, |
||
168 | 'extension' => $rule->extension, |
||
169 | 'callerid' => $extension ? $extension->getRepresent() : '', |
||
170 | 'note' => $rule->note, |
||
171 | 'status' => in_array($rule->id, $allowedRulesIds, true) ? '' : 'disabled', |
||
172 | ]; |
||
173 | |||
174 | $routingTable[] = $values; |
||
175 | } |
||
176 | $this->view->rules = $routingTable; |
||
177 | } |
||
326 |