sibprogrammer/owp

View on GitHub
app/controllers/admin/virtual_servers_controller.rb

Summary

Maintainability
D
3 days
Test Coverage

File virtual_servers_controller.rb has 331 lines of code (exceeds 250 allowed). Consider refactoring.
Open

include ActionView::Helpers::TextHelper

class Admin::VirtualServersController < Admin::Base
  before_filter :superadmin_required, :only => [:list_data, :delete, :create, :clone, :migrate]
  before_filter :set_server_by_id, :only => [ :clone, :migrate, :create_template, :get_properties, :get_stats, :get_limits ]
Severity: Minor
Found in app/controllers/admin/virtual_servers_controller.rb - About 3 hrs to fix

    Class VirtualServersController has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Admin::VirtualServersController < Admin::Base
      before_filter :superadmin_required, :only => [:list_data, :delete, :create, :clone, :migrate]
      before_filter :set_server_by_id, :only => [ :clone, :migrate, :create_template, :get_properties, :get_stats, :get_limits ]
    
      def list
    Severity: Minor
    Found in app/controllers/admin/virtual_servers_controller.rb - About 2 hrs to fix

      Method stat_details has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def stat_details
          @virtual_server = VirtualServer.find_by_id(params[:id])
          redirect_to :controller => 'dashboard' and return if !@virtual_server or !@current_user.can_control(@virtual_server)
      
          @up_level = '/admin/virtual-servers/show?id=' + @virtual_server.id.to_s
      Severity: Minor
      Found in app/controllers/admin/virtual_servers_controller.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method get_usage_stats has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def get_usage_stats(virtual_server)
            is_running = 'running' == virtual_server.real_state
      
            stats = []
      
      
      Severity: Major
      Found in app/controllers/admin/virtual_servers_controller.rb - About 2 hrs to fix

        Method stat_details has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def stat_details
            @virtual_server = VirtualServer.find_by_id(params[:id])
            redirect_to :controller => 'dashboard' and return if !@virtual_server or !@current_user.can_control(@virtual_server)
        
            @up_level = '/admin/virtual-servers/show?id=' + @virtual_server.id.to_s
        Severity: Minor
        Found in app/controllers/admin/virtual_servers_controller.rb - About 1 hr to fix

          Method virtual_server_properties has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def virtual_server_properties(virtual_server)
                params = [
                  {
                    :parameter => t('admin.virtual_servers.form.create_server.field.identity'),
                    :value => virtual_server.identity,
          Severity: Minor
          Found in app/controllers/admin/virtual_servers_controller.rb - About 1 hr to fix

            Method virtual_server_properties has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                def virtual_server_properties(virtual_server)
                  params = [
                    {
                      :parameter => t('admin.virtual_servers.form.create_server.field.identity'),
                      :value => virtual_server.identity,
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method load_data has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def load_data
                virtual_server = VirtualServer.find_by_id(params[:id])
                redirect_to :controller => 'dashboard' and return if !virtual_server or !@current_user.can_control(virtual_server)
            
                render :json => { :success => true, :data => {
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method reinstall has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def reinstall
                virtual_server = VirtualServer.find_by_id(params[:id])
                if !virtual_server or !@current_user.can_control(virtual_server) or !@current_user.can_reinstall_ve?
                  redirect_to :controller => 'dashboard' and return
                end
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb - About 45 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method get_usage_stats has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_usage_stats(virtual_server)
                  is_running = 'running' == virtual_server.real_state
            
                  stats = []
            
            
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method change_settings has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def change_settings
                virtual_server = VirtualServer.find_by_id(params[:id])
                redirect_to :controller => 'dashboard' and return if !virtual_server or !@current_user.can_control(virtual_server)
            
                if !params[:password].blank?
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def create
                hardware_server = HardwareServer.find_by_id(params[:hardware_server_id])
                redirect_to :controller => 'hardware_servers', :action => 'list' if !hardware_server
            
                virtual_server = (params[:id].to_i > 0) ? VirtualServer.find_by_id(params[:id]) : VirtualServer.new
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                  if counter and is_running and (counter.limit.to_i > 0)
                    stats << {
                      :parameter => t('admin.virtual_servers.stats.field.disk_usage'),
                      :value => {
                        'text' => t(
            Severity: Major
            Found in app/controllers/admin/virtual_servers_controller.rb and 1 other location - About 2 hrs to fix
            app/controllers/admin/virtual_servers_controller.rb on lines 377..393

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 81.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                  if counter and is_running and (counter.limit.to_i > 0)
                    stats << {
                      :parameter => t('admin.virtual_servers.stats.field.memory_usage'),
                      :value => {
                        'text' => t(
            Severity: Major
            Found in app/controllers/admin/virtual_servers_controller.rb and 1 other location - About 2 hrs to fix
            app/controllers/admin/virtual_servers_controller.rb on lines 357..373

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 81.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                @ram_usage = !is_running ? [] : Watchdog.get_ve_counters_queue('_memory', @virtual_server.id).map do |counter|
                  ram = counter[:held].to_i / (1024 * 1024)
                  @ram_max = ram if ram > @ram_max
                  { 'time' => counter[:created_at].min, 'usage' => ram }
                end
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb and 1 other location - About 40 mins to fix
            app/controllers/admin/virtual_servers_controller.rb on lines 141..147

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 37.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                @disk_usage = !is_running ? [] : Watchdog.get_ve_counters_queue('_diskspace', @virtual_server.id).map do |counter|
                  diskspace = counter[:held].to_i / (1024 * 1024)
                  @disk_max = diskspace if diskspace > @disk_max
                  { 'time' => counter[:created_at].min, 'usage' => diskspace }
                end
            Severity: Minor
            Found in app/controllers/admin/virtual_servers_controller.rb and 1 other location - About 40 mins to fix
            app/controllers/admin/virtual_servers_controller.rb on lines 134..140

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 37.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status