Conditions | 10 |
Paths | 7 |
Total Lines | 43 |
Code Lines | 30 |
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 |
||
82 | public function save() |
||
83 | { |
||
84 | if (!empty($this->lead) || !empty($this->contacts)) { |
||
85 | $lead = null; |
||
86 | if (!empty($this->lead)) { |
||
87 | $lead = $this->lead->getRaw(); |
||
88 | if (!empty($this->notes)) { |
||
89 | foreach ($this->notes as $note) { |
||
90 | $lead['notes'][] = $note->getRaw(); |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | $contacts = array(); |
||
95 | foreach ($this->contacts as $contact) { |
||
96 | $contacts[] = $contact->getRaw(); |
||
97 | } |
||
98 | $companies = array(); |
||
99 | foreach ($this->companies as $company) { |
||
100 | $companies[] = $company->getRaw(); |
||
101 | } |
||
102 | $request['add'] = array( |
||
|
|||
103 | array( |
||
104 | 'source_name' => 'DrillCoder AmoCRM Wrap', |
||
105 | 'created_at' => date('U'), |
||
106 | 'pipeline_id' => $this->pipelineId, |
||
107 | 'incoming_entities' => array( |
||
108 | 'leads' => array($lead), |
||
109 | 'contacts' => $contacts, |
||
110 | 'companies' => $companies, |
||
111 | ), |
||
112 | 'incoming_lead_info' => array( |
||
113 | 'form_id' => 25, |
||
114 | 'form_page' => $this->formName, |
||
115 | ), |
||
116 | ), |
||
117 | ); |
||
118 | $response = AmoCRM::cUrl('api/v2/incoming_leads/form', $request); |
||
119 | if ($response !== null && $response->status === 'success') { |
||
120 | $this->id = $response->data[0]; |
||
121 | return $this; |
||
122 | } |
||
123 | } |
||
124 | throw new AmoWrapException('Не удалось сохранить заявку в неразобранное'); |
||
125 | } |
||
144 | } |