yegor256/mailanes

View on GitHub

Showing 27 of 41 total issues

File mailanes.rb has 922 lines of code (exceeds 250 allowed). Consider refactoring.
Open

$stdout.sync = true

require 'geoplugin'
require 'get_process_mem'
require 'glogin'
Severity: Major
Found in mailanes.rb - About 2 days to fix

    Method upload has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

      def upload(file, source: '')
        deliveries = Deliveries.new(pgsql: @pgsql)
        line = 1
        File.readlines(file).each do |t|
          begin
    Severity: Minor
    Found in objects/recipients.rb - About 5 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 deliver_smtp has 129 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def deliver_smtp(content, recipient, codec, delivery)
        html = with_utm(
          Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(content),
          delivery
        )
    Severity: Major
    Found in objects/letter.rb - About 5 hrs to fix

      Method deliver_smtp has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

        def deliver_smtp(content, recipient, codec, delivery)
          html = with_utm(
            Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(content),
            delivery
          )
      Severity: Minor
      Found in objects/letter.rb - About 4 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

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

      require 'yaml'
      require 'mail'
      require 'uuidtools'
      require 'timeout'
      require 'pg'
      Severity: Minor
      Found in objects/letter.rb - About 3 hrs to fix

        Class Letter has 28 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class Letter
          # When can't deliver
          class CantDeliver < StandardError; end
        
          attr_reader :id
        Severity: Minor
        Found in objects/letter.rb - About 3 hrs to fix

          Method match has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
          Open

            def match(body, regex, tbot, delivery: false)
              body.scan(regex).each do |id, encrypted, did|
                next if id.nil? || encrypted.nil?
                begin
                  plain = id.to_i
          Severity: Minor
          Found in objects/bounces.rb - About 3 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

          Class Campaign has 23 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class Campaign
            attr_reader :id
          
            def initialize(id:, pgsql:, hash: {})
              raise "Invalid ID: #{id} (#{id.class.name})" unless id.is_a?(Integer)
          Severity: Minor
          Found in objects/campaign.rb - About 2 hrs to fix

            Method match has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def match(body, regex, tbot, delivery: false)
                body.scan(regex).each do |id, encrypted, did|
                  next if id.nil? || encrypted.nil?
                  begin
                    plain = id.to_i
            Severity: Minor
            Found in objects/bounces.rb - About 1 hr to fix

              Method query has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.query(campaign = 0)
                  chistory = [
                    'SELECT COUNT(*) FROM delivery',
                    'WHERE delivery.campaign=c.id',
                    'AND delivery.created > NOW() - INTERVAL \'1 DAY\''
              Severity: Minor
              Found in objects/pipeline.rb - About 1 hr to fix

                Method add has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def add(email, first: '', last: '', source: '')
                    raise UserError, "Invalid email #{email.inspect}" unless email =~ Recipients::REGEX
                    recipient = Recipient.new(
                      id: @pgsql.exec(
                        'INSERT INTO recipient (list, email, first, last, source) VALUES ($1, $2, $3, $4, $5) RETURNING id',
                Severity: Minor
                Found in objects/recipients.rb - About 1 hr to fix

                  Method absorb has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def absorb(list)
                      @pgsql.transaction do |t|
                        t.exec(
                          [
                            'DELETE FROM delivery WHERE id IN',
                  Severity: Minor
                  Found in objects/list.rb - About 1 hr to fix

                    Method all has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def all(query: '', limit: 100, active_only: false, in_list_only: true)
                        q = [
                          'SELECT recipient.* FROM recipient',
                          'JOIN list ON list.id = recipient.list AND list.owner = $1',
                          'WHERE',
                    Severity: Minor
                    Found in objects/recipients.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 cfg has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def cfg(default, *items)
                        result = yaml
                        items.each do |i|
                          result = result[i]
                          break if result.nil?
                    Severity: Minor
                    Found in objects/letter.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 upload has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def upload(file, source: '')
                        deliveries = Deliveries.new(pgsql: @pgsql)
                        line = 1
                        File.readlines(file).each do |t|
                          begin
                    Severity: Minor
                    Found in objects/recipients.rb - About 1 hr to fix

                      Method deactivate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def deactivate
                          @pgsql.exec('SELECT * FROM letter WHERE active=true').each do |r|
                            letter = Letter.new(id: r['id'].to_i, pgsql: @pgsql, hash: r)
                            next unless letter.yaml['until'] && Time.parse(letter.yaml['until']) < Time.now
                            letter.toggle
                      Severity: Minor
                      Found in objects/pipeline.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 yaml= has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def yaml=(yaml)
                          @pgsql.exec('UPDATE campaign SET yaml=$1 WHERE id=$2', [YamlDoc.new(yaml).save, @id])
                          yml = YamlDoc.new(yaml).load
                          if yml['decoy']
                            raise UserError, 'Decoy amount must be set' if yml['decoy']['amount'].nil?
                      Severity: Minor
                      Found in objects/campaign.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 move has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def move(inc = 1)
                          raise "Invalid direction #{inc.inspect}" if inc != 1 && inc != -1
                          @pgsql.transaction do |t|
                            other = t.exec(
                              [
                      Severity: Minor
                      Found in objects/letter.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 csv has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def csv
                          CSV.generate(headers: true) do |csv|
                            csv << [
                              'Email',
                              'First name',
                      Severity: Minor
                      Found in objects/recipients.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 initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        def initialize(host, port, login, password, codec, pgsql:, log: Loog::NULL)
                      Severity: Minor
                      Found in objects/bounces.rb - About 35 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language