3scale/porta

View on GitHub
lib/developer_portal/lib/liquid/drops/account.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Account has 43 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Account < Drops::Model

      info %{
A developer account. See `User` drop if you are looking for the email addresses or similar information.
      }
Severity: Minor
Found in lib/developer_portal/lib/liquid/drops/account.rb - About 5 hrs to fix

    File account.rb has 265 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Liquid
      module Drops
        class Account < Drops::Model
    
          info %{
    Severity: Minor
    Found in lib/developer_portal/lib/liquid/drops/account.rb - About 2 hrs to fix

      Liquid::Drops::Account has at least 43 methods
      Open

          class Account < Drops::Model

      Too Many Methods is a special case of LargeClass.

      Example

      Given this configuration

      TooManyMethods:
        max_methods: 3

      and this code:

      class TooManyMethods
        def one; end
        def two; end
        def three; end
        def four; end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [1]:TooManyMethods has at least 4 methods (TooManyMethods)

      Liquid::Drops::Account#extra_fields_plain_text calls '@model.extra_fields' 2 times
      Open

              if @model.extra_fields.present?
                @model.extra_fields.each_pair do |name, value|

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      Liquid::Drops::Account#fields_plain_text calls '@model.defined_fields' 2 times
      Open

              if @model.defined_fields.present?
                @model.defined_fields.each do |field|

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      Liquid::Drops::Account#fields_plain_text calls 'field.name' 3 times
      Open

                  if @model.field(field.name).present? && field.visible_for?(admin_user)
                    result << "* #{@model.field_label(field.name)}: #{@model.field_value(field.name)}\n"

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      Liquid::Drops::Account assumes too much for instance variable '@model'
      Open

          class Account < Drops::Model

      Classes should not assume that instance variables are set or present outside of the current class definition.

      Good:

      class Foo
        def initialize
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Good as well:

      class Foo
        def foo?
          bar == :foo
        end
      
        def bar
          @bar ||= :foo
        end
      end

      Bad:

      class Foo
        def go_foo!
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Example

      Running Reek on:

      class Dummy
        def test
          @ivar
        end
      end

      would report:

      [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

      Note that this example would trigger this smell warning as well:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          @omg
        end
      end

      The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

      class Parent
        attr_reader :omg
      
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

      If you don't want to expose those methods as public API just make them private like this:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      
        private
        attr_reader :omg
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Current Support in Reek

      An instance variable must:

      • be set in the constructor
      • or be accessed through a method with lazy initialization / memoization.

      If not, Instance Variable Assumption will be reported.

      Liquid::Drops::Account assumes too much for instance variable '@latest_messages'
      Open

          class Account < Drops::Model

      Classes should not assume that instance variables are set or present outside of the current class definition.

      Good:

      class Foo
        def initialize
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Good as well:

      class Foo
        def foo?
          bar == :foo
        end
      
        def bar
          @bar ||= :foo
        end
      end

      Bad:

      class Foo
        def go_foo!
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Example

      Running Reek on:

      class Dummy
        def test
          @ivar
        end
      end

      would report:

      [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

      Note that this example would trigger this smell warning as well:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          @omg
        end
      end

      The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

      class Parent
        attr_reader :omg
      
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

      If you don't want to expose those methods as public API just make them private like this:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      
        private
        attr_reader :omg
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Current Support in Reek

      An instance variable must:

      • be set in the constructor
      • or be accessed through a method with lazy initialization / memoization.

      If not, Instance Variable Assumption will be reported.

      Liquid::Drops::Account#extra_fields_plain_text calls '@model.field(name)' 2 times
      Open

                  if @model.field(name).present? &&
                      @model.field(name).visible_for?(admin_user)

      Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

      Reek implements a check for Duplicate Method Call.

      Example

      Here's a very much simplified and contrived example. The following method will report a warning:

      def double_thing()
        @other.thing + @other.thing
      end

      One quick approach to silence Reek would be to refactor the code thus:

      def double_thing()
        thing = @other.thing
        thing + thing
      end

      A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

      class Other
        def double_thing()
          thing + thing
        end
      end

      The approach you take will depend on balancing other factors in your code.

      Liquid::Drops::Account assumes too much for instance variable '@unread_messages'
      Open

          class Account < Drops::Model

      Classes should not assume that instance variables are set or present outside of the current class definition.

      Good:

      class Foo
        def initialize
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Good as well:

      class Foo
        def foo?
          bar == :foo
        end
      
        def bar
          @bar ||= :foo
        end
      end

      Bad:

      class Foo
        def go_foo!
          @bar = :foo
        end
      
        def foo?
          @bar == :foo
        end
      end

      Example

      Running Reek on:

      class Dummy
        def test
          @ivar
        end
      end

      would report:

      [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

      Note that this example would trigger this smell warning as well:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          @omg
        end
      end

      The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

      class Parent
        attr_reader :omg
      
        def initialize(omg)
          @omg = omg
        end
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

      If you don't want to expose those methods as public API just make them private like this:

      class Parent
        def initialize(omg)
          @omg = omg
        end
      
        private
        attr_reader :omg
      end
      
      class Child < Parent
        def foo
          omg
        end
      end

      Current Support in Reek

      An instance variable must:

      • be set in the constructor
      • or be accessed through a method with lazy initialization / memoization.

      If not, Instance Variable Assumption will be reported.

      There are no issues that match your filters.

      Category
      Status