ucberkeley/moocchat

View on GitHub

Showing 132 of 132 total issues

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

  protected void initOptions() {
    opt.addOption(ARG_INPUT, true,
        "(required) The input file to use (in comma-delimited format, ie. helloworld.input)");
    opt.addOption(ARG_QUESTION, true,
        "(required) The question file to use (ie. helloworld.question)");
Severity: Major
Found in turk/src/com/amazonaws/mturk/cmd/LoadHITs.java and 1 other location - About 1 hr to fix
turk/src/com/amazonaws/mturk/cmd/MakeTemplate.java on lines 48..63

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 87.

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

Method runCommand has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected void runCommand(CommandLine cmdLine) throws Exception {
      if (!cmdLine.hasOption(ARG_QUALTYPE) &&
          !cmdLine.hasOption(ARG_INPUT_FILE)) {
        log.error("Either -" + ARG_QUALTYPE + " or -" + ARG_INPUT_FILE + " must be passed");
        System.exit(-1);
Severity: Minor
Found in turk/src/com/amazonaws/mturk/cmd/AssignQualification.java - About 1 hr to fix

    Method runCommand has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      protected void runCommand(CommandLine cmdLine) throws Exception {
    
          if (!cmdLine.hasOption(ARG_QUALTYPE) &&
              !cmdLine.hasOption(ARG_INPUT_FILE)) {
              log.error("Either -" + ARG_QUALTYPE + " or -" + ARG_INPUT_FILE + " should be passed");
    Severity: Minor
    Found in turk/src/com/amazonaws/mturk/cmd/UpdateQualificationType.java - About 1 hr to fix

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

        private String[] getHits() {
          HIT[] hits = null;
          List<String> ret = new ArrayList<String>();
          SearchHITsResult result = null;    
          String[] responseGroup = new String [] { "Minimal", "HITDetail" };
      Severity: Minor
      Found in turk/src/com/amazonaws/mturk/cmd/ResetAccount.java - 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 getSummary has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public Map<String, List<String>> getSummary(String resultsFile) throws ParseException {
      
              // hitid is always required.
              String[] requiredFields = new String[]{
                      "annotation", "Answer.inappropriate", "assignments"

        Method rewriteHeaders has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private void rewriteHeaders(String source, String destination) throws IOException {
              BufferedReader reader = null;
              Writer writer = null;
              String newline = System.getProperty("line.separator");
              
        Severity: Minor
        Found in turk/src/com/amazonaws/mturk/util/HITResultProcessor.java - About 1 hr to fix

          Function update has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function update() {
              $.ajax({
                  url:'https://moocchat.herokuapp.com/get_current_timestamp_utc/',
                  dataType: 'jsonp',
                  type: 'GET',
          Severity: Minor
          Found in public/moocchat_global_notification.js - About 1 hr to fix

            Function sendMessages has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              sendMessages: function() {
                var self = this;
                if(this.isBoth()){
                  this.sendChatMessageButton.click(function(event) {
                    event.preventDefault();
            Severity: Minor
            Found in app/assets/javascripts/web_socket.js - About 1 hr to fix

              Method sessions_show has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def sessions_show
                  eventlog_sessions = eventlog_sessions(EventLog.where(created_at: parse_datetime_picker_date(params[:datetime_start])..parse_datetime_picker_date(params[:datetime_end])))
              
                  @sessions = []
                  eventlog_sessions.each do |session_events|
              Severity: Minor
              Found in app/controllers/reports_controller.rb - About 1 hr to fix

                Function showWelcomeMessage has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  showWelcomeMessage: function(){
                    if (this.group.length == 1) {
                      this.showMessage("No one is currently available to chat with you. You may use this chatroom to reflect on the question. Click the end button above when done.", "system");
                    } else if (this.group.length == 2) {
                      var you_learner = '';
                Severity: Minor
                Found in app/assets/javascripts/web_socket.js - About 1 hr to fix

                  Method parseHitAssignments has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static Map<String, List<String[]>> parseHitAssignments(
                              String resultsFile, String[] requiredFields, int[] fieldIndicesPlaceholder, char fieldSeparator) {
                  
                          Map<String, List<String[]>> hitAssignments = new LinkedHashMap<String, List<String[]>>();
                          try {
                  Severity: Minor
                  Found in turk/src/com/amazonaws/mturk/cmd/summary/SummaryUtils.java - About 1 hr to fix

                    Method runCommand has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      protected void runCommand(CommandLine cmdLine) throws Exception {
                        if (!cmdLine.hasOption(QUAL_TYPE) &&
                            !cmdLine.hasOption(INPUT_FILE)) {
                    
                          log.error("Either -" + QUAL_TYPE + " or -" + INPUT_FILE + " should be passed");
                    Severity: Minor
                    Found in turk/src/com/amazonaws/mturk/cmd/EvaluateQualificationRequests.java - About 1 hr to fix

                      Method getHits has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        private String[] getHits() {
                          HIT[] hits = null;
                          List<String> ret = new ArrayList<String>();
                          SearchHITsResult result = null;    
                          String[] responseGroup = new String [] { "Minimal", "HITDetail" };
                      Severity: Minor
                      Found in turk/src/com/amazonaws/mturk/cmd/ResetAccount.java - About 1 hr to fix

                        Function keyboardEvent has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            keyboardEvent: function(type, options) {
                                var evt;
                        
                                var e = $.extend({ bubbles: true, cancelable: true, view: window,
                                    ctrlKey: false, altKey: false, shiftKey: false, metaKey: false,
                        Severity: Minor
                        Found in app/assets/javascripts/jquery.simulate.js - About 1 hr to fix

                          Method approveAssignmentsInFile has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            public void approveAssignmentsInFile(String fileName) throws IOException {
                              if (fileName == null) {
                                throw new IllegalArgumentException("fileName must not be null");
                              }
                              
                          Severity: Minor
                          Found in turk/src/com/amazonaws/mturk/cmd/ApproveWork.java - About 1 hr to fix

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

                              protected String[] getFieldValuesFromFile(String fileName, String fieldName) throws IOException {
                                
                                HITDataCSVReader csvReader = new HITDataCSVReader(fileName);    
                                
                                // check that we have a header 
                            Severity: Minor
                            Found in turk/src/com/amazonaws/mturk/cmd/AbstractCmd.java - 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 approveHitsInFile has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                              public void approveHitsInFile(String fileName) throws IOException {
                                if (fileName == null) {
                                  throw new IllegalArgumentException("fileName must not be null");
                                }
                                
                            Severity: Minor
                            Found in turk/src/com/amazonaws/mturk/cmd/ApproveWork.java - 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 getHeaderRow has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                              private String[] getHeaderRow(HITResults r) {
                                if (headerFields == null) {
                                  headerFields = new ArrayList<String>();
                                  
                                  for (HITProperties.HITField field : HITProperties.HIT_FIELDS) {
                            Severity: Minor
                            Found in turk/src/com/amazonaws/mturk/cmd/GetResults.java - 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 ensure_setup_socket_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def ensure_setup_socket_for(env)
                                channel, my_position, my_id = channel_and_position_from_url(env['ORIGINAL_FULLPATH'])
                                unless @groups.has_key?(channel) && @groups[channel][my_position]
                                  ws = Faye::WebSocket.new(env, nil, {ping: KEEPALIVE_TIME })
                                  @groups[channel] ||= []
                            Severity: Minor
                            Found in app/middleware/chat_server.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

                            Function initialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                              initialize: function(chatGroup,taskid,rails_mode, type) {
                                this.type = type;
                                if(typeof chatGroup == "number"){
                                  this.group = [chatGroup];
                                } else{
                            Severity: Minor
                            Found in app/assets/javascripts/web_socket.js - 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

                            Severity
                            Category
                            Status
                            Source
                            Language