arthurnn/apn_sender

View on GitHub

Showing 3 of 3 total issues

Method initialize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def initialize(args)
      @options = {worker_count: 1, delay: 5}

      optparse = OptionParser.new do |opts|
        opts.banner = "Usage: #{File.basename($0)} [options] start|stop|restart|run"
Severity: Minor
Found in lib/apn/sender_daemon.rb - About 1 hr to fix

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

      def package
        str = encode(@notification_hash)
    
        if APN.truncate_alert && str.bytesize > @max_bytes
          max_bytesize = @max_bytes - (str.bytesize - alert.bytesize)
    Severity: Minor
    Found in lib/apn/payload.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 daemonize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def daemonize
          @options[:worker_count].times do |worker_index|
            process_name = @options[:worker_count] == 1 ? "apn_sender" : "apn_sender.#{worker_index}"
            pids_dir = defined?(Rails) ? "#{::RAILS_ROOT}/tmp/pids" : "tmp/pids"
            Daemons.run_proc(process_name, :dir => pids_dir, :dir_mode => :normal, :ARGV => @args) do |*args|
    Severity: Minor
    Found in lib/apn/sender_daemon.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

    Severity
    Category
    Status
    Source
    Language