DEV: improve the code readability.

DEV: improve the code readability.

a0e0b1ef4bc15682e681c43a9c037711c99dbce3

diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index c5c61679f6..d9647293f5 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -359,7 +359,9 @@ class PostRevisor
     end
 
     POST_TRACKED_FIELDS.each do |field|
-      @post.public_send("#{field}=", @fields[field]) if @fields.has_key?(field) || (should_create_new_version? && field == "edit_reason")
+      if @fields.has_key?(field) || (should_create_new_version? && field == "edit_reason")
+        @post.public_send("#{field}=", @fields[field])
+      end
     end
 
     @post.last_editor_id = @editor.id

GitHub sha: b0f72ca1

1 Like

Maybe we should extract this out of the loop so we don’t have to test for it for every fields?

POST_TRACKED_FIELDS.each do |field| 
  @post.public_send("#{field}=", @fields[field]) if @fields.has_key?(field)
end

@post.edit_reason = @fields["edit_reason"] if should_create_new_version?
1 Like

https://review.discourse.org/t/dev-improve-code-readability-8967/9089