Browse Source

Replace unless with if ! (project-wide)

Ryan Lue 6 years ago
parent
commit
04055f7095

+ 2 - 2
app/controllers/concerns/creates_ticket_articles.rb

@@ -36,7 +36,7 @@ module CreatesTicketArticles
       clean_params.delete(:sender)
       clean_params.delete(:origin_by_id)
       type = Ticket::Article::Type.lookup(id: clean_params[:type_id])
-      unless type.name.match?(/^(note|web)$/)
+      if !type.name.match?(/^(note|web)$/)
         clean_params[:type_id] = Ticket::Article::Type.lookup(name: 'note').id
       end
       clean_params.delete(:type)
@@ -89,7 +89,7 @@ module CreatesTicketArticles
           preferences[store_key] = attachment[key]
         end
 
-        unless attachment[:data].match?(%r{^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$})
+        if !attachment[:data].match?(%r{^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$})
           raise Exceptions::UnprocessableEntity, "Invalid base64 for attachment with index '#{index}'"
         end
 

+ 1 - 3
app/controllers/form_controller.rb

@@ -67,9 +67,7 @@ class FormController < ApplicationController
         Rails.logger.info "Can't verify email #{params[:email]}: #{message}"
 
         # ignore 450, graylistings
-        unless message.match?(/450/)
-          errors['email'] = message
-        end
+        errors['email'] = message if !message.match?(/450/)
       end
     end
 

+ 1 - 1
app/controllers/import_zendesk_controller.rb

@@ -39,7 +39,7 @@ class ImportZendeskController < ApplicationController
     end
 
     # since 2016-10-15 a redirect to a marketing page has been implemented
-    unless response.body.match?(/#{params[:url]}/)
+    if !response.body.match?(/#{params[:url]}/)
       render json: {
         result: 'invalid',
         message_human: 'Hostname not found!',

+ 1 - 1
app/controllers/integration/sipgate_controller.rb

@@ -13,7 +13,7 @@ class Integration::SipgateController < ApplicationController
 
       # check if call need to be blocked
       block_caller_ids.each do |item|
-        next unless item[:caller_id] == params['from']
+        next if item[:caller_id] != params['from']
         xml = Builder::XmlMarkup.new(indent: 2)
         xml.instruct!
         content = xml.Response(onHangup: url, onAnswer: url) do

+ 1 - 1
app/controllers/settings_controller.rb

@@ -45,7 +45,7 @@ class SettingsController < ApplicationController
     end
 
     # validate image
-    unless clean_params[:logo].match?(/^data:image/i)
+    if !clean_params[:logo].match?(/^data:image/i)
       render json: {
         result: 'invalid',
         message: 'Invalid payload, need data:image in logo param',

+ 1 - 1
app/models/application_model/can_associations.rb

@@ -376,7 +376,7 @@ returns
         next if !assoc_name.to_s.end_with?('s')
         ref_names = "#{assoc_name.to_s.chomp('s')}_ids"
         generic_object_tmp = new
-        next unless generic_object_tmp.respond_to?(ref_names) # if we do have an _ids attribute
+        next if !generic_object_tmp.respond_to?(ref_names) # if we do have an _ids attribute
         next if data[ref_names.to_sym] # next if we have already the _ids filled
 
         # get association class and do lookup

+ 1 - 1
app/models/channel/driver/pop3.rb

@@ -91,7 +91,7 @@ returns
         next if !mail
 
         # check how many content messages we have, for notice used
-        unless mail.match?(/x-zammad-ignore/i)
+        if !mail.match?(/x-zammad-ignore/i)
           content_messages += 1
           break if content_max_check < content_messages
         end

+ 1 - 1
app/models/channel/email_parser.rb

@@ -863,7 +863,7 @@ module Mail
   module Encodings
     def self.value_decode(str)
       # Optimization: If there's no encoded-words in the string, just return it
-      return str unless str.index('=?')
+      return str if !str.index('=?')
 
       str = str.gsub(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's
 

+ 3 - 7
app/models/channel/filter/identify_sender.rb

@@ -144,13 +144,9 @@ module Channel::Filter::IdentifySender
   end
 
   def self.user_create(data, role_ids = nil)
-    unless data[:email].match?(/@/)
-      data[:email] += '@local'
-    end
-    user = User.find_by(email: data[:email].downcase)
-    if !user
-      user = User.find_by(login: data[:email].downcase)
-    end
+    data[:email] += '@local' if !data[:email].match?(/@/)
+    user = User.find_by(email: data[:email].downcase) ||
+           User.find_by(login: data[:email].downcase)
 
     # check if firstname or lastname need to be updated
     if user

+ 1 - 1
app/models/concerns/can_csv_import.rb

@@ -296,7 +296,7 @@ returns
           row.push record[key]
         end
         rows.push row
-        next unless rows_to_add.count.positive?
+        next if rows_to_add.count.zero?
         rows_to_add.each do |item|
           rows.push item
         end

Some files were not shown because too many files changed in this diff