Conditions | 11 |
Paths | 128 |
Total Lines | 64 |
Code Lines | 36 |
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 |
||
157 | public function save() |
||
158 | { |
||
159 | $this->_content->title = $this->title; |
||
160 | $this->_content->text = $this->text; |
||
161 | $this->_content->path = $this->path; |
||
162 | $this->_content->category_id = $this->categoryId; |
||
163 | $this->_content->author_id = $this->authorId; |
||
164 | $this->_content->display = $this->display; |
||
|
|||
165 | $this->_content->meta_title = $this->metaTitle; |
||
166 | $this->_content->meta_keywords = $this->metaKeywords; |
||
167 | $this->_content->meta_description = $this->metaDescription; |
||
168 | $this->_content->source = $this->source; |
||
169 | $this->_content->important = (int)$this->important; |
||
170 | // check if rating is changed |
||
171 | if ((int)$this->addRating !== 0) { |
||
172 | $this->_content->rating += (int)$this->addRating; |
||
173 | } |
||
174 | // check if special comment hash is exist |
||
175 | if ($this->_new || Str::length($this->_content->comment_hash) < 32) { |
||
176 | $this->_content->comment_hash = $this->generateCommentHash(); |
||
177 | } |
||
178 | |||
179 | // check if date is updated |
||
180 | if (!Str::likeEmpty($this->createdAt) && !Str::startsWith('0000', Date::convertToDatetime($this->createdAt, Date::FORMAT_SQL_TIMESTAMP))) { |
||
181 | $this->_content->created_at = Date::convertToDatetime($this->createdAt, Date::FORMAT_SQL_TIMESTAMP); |
||
182 | } |
||
183 | |||
184 | // save poster data |
||
185 | $posterPath = '/upload/gallery/' . $this->galleryFreeId . '/orig/' . $this->poster; |
||
186 | if (File::exist($posterPath)) { |
||
187 | $this->_content->poster = $this->poster; |
||
188 | } |
||
189 | |||
190 | // get temporary gallery id |
||
191 | $tmpGalleryId = $this->galleryFreeId; |
||
192 | |||
193 | // save row |
||
194 | $this->_content->save(); |
||
195 | |||
196 | // update tags data in special table (relation: content->content_tags = oneToMany) |
||
197 | ContentTag::where('content_id', '=', $this->_content->id)->delete(); |
||
198 | $insertData = []; |
||
199 | foreach ($this->metaKeywords as $lang => $keys) { |
||
200 | // split keywords to tag array |
||
201 | $tags = explode(',', $keys); |
||
202 | foreach ($tags as $tag) { |
||
203 | // cleanup tag from white spaces |
||
204 | $tag = trim($tag); |
||
205 | // prepare data to insert |
||
206 | if (Str::length($tag) > 0) { |
||
207 | $insertData[] = [ |
||
208 | 'content_id' => $this->_content->id, |
||
209 | 'lang' => $lang, |
||
210 | 'tag' => $tag |
||
211 | ]; |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | // insert tags |
||
216 | ContentTag::insert($insertData); |
||
217 | |||
218 | // move files |
||
219 | if ($tmpGalleryId !== $this->_content->id) { |
||
220 | Directory::rename('/upload/gallery/' . $tmpGalleryId, $this->_content->id); |
||
221 | } |
||
269 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.