warlof/slackbot

View on GitHub
src/Http/Controllers/Services/Traits/SlackApiConnector.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

    private function getConnector() : SlackApi
    {
        if (!is_null($this->slack))
            return $this->slack;

Severity: Minor
Found in src/Http/Controllers/Services/Traits/SlackApiConnector.php - About 1 hr to fix

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

        private function fetchSlackConversationMembers(string $channel_id, string $cursor = null) : array
        {
            sleep(1);
    
            $this->getConnector()->setQueryString([
    Severity: Minor
    Found in src/Http/Controllers/Services/Traits/SlackApiConnector.php - About 1 hr to fix

      Define a constant instead of duplicating this literal "/conversations.list" 3 times.
      Open

              $response = Cache::tags(['conversations'])->get($this->getConnector()->buildDataUri('/conversations.list'));

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "public_channel" 3 times.
      Open

                  'types' => implode(',', ['public_channel', 'private_channel']),

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Add curly braces around the nested statement(s).
      Open

              if (!is_null($cursor))

      While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

      Noncompliant Code Example

      if (condition)  // Noncompliant
        executeSomething();
      

      Compliant Solution

      if (condition) {
        executeSomething();
      }
      

      See

      • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
      • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
      • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

      Define a constant instead of duplicating this literal "response_metadata" 3 times.
      Open

              if (property_exists($response, 'response_metadata') && $response->response_metadata->next_cursor != '') {

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Add curly braces around the nested statement(s).
      Open

              if (! is_null($cursor))

      While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

      Noncompliant Code Example

      if (condition)  // Noncompliant
        executeSomething();
      

      Compliant Solution

      if (condition) {
        executeSomething();
      }
      

      See

      • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
      • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
      • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

      Define a constant instead of duplicating this literal "cursor" 3 times.
      Open

                  $query_parameters['cursor'] = $cursor;

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Add curly braces around the nested statement(s).
      Open

              if (is_null(setting('warlof.slackbot.credentials.access_token', true)))

      While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

      Noncompliant Code Example

      if (condition)  // Noncompliant
        executeSomething();
      

      Compliant Solution

      if (condition) {
        executeSomething();
      }
      

      See

      • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
      • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
      • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

      Define a constant instead of duplicating this literal "private_channel" 3 times.
      Open

                  'types' => implode(',', ['public_channel', 'private_channel']),

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Add curly braces around the nested statement(s).
      Open

              if (!is_null($this->slack))

      While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

      Noncompliant Code Example

      if (condition)  // Noncompliant
        executeSomething();
      

      Compliant Solution

      if (condition) {
        executeSomething();
      }
      

      See

      • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
      • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
      • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

      Define a constant instead of duplicating this literal "members" 3 times.
      Open

              $response = Cache::tags(['conversations', 'members'])->get($this->getConnector()->buildDataUri('/conversations.members'));

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "conversations" 4 times.
      Open

              $response = Cache::tags(['conversations'])->get($this->getConnector()->buildDataUri('/conversations.list'));

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "exclude_archived" 3 times.
      Open

                  'exclude_archived' => true,

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "types" 3 times.
      Open

                  'types' => implode(',', ['public_channel', 'private_channel']),

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Define a constant instead of duplicating this literal "/conversations.members" 3 times.
      Open

              $response = Cache::tags(['conversations', 'members'])->get($this->getConnector()->buildDataUri('/conversations.members'));

      Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

      On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

      Noncompliant Code Example

      With the default threshold of 3:

      function run() {
        prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
        execute('action1');
        release('action1');
      }
      

      Compliant Solution

      ACTION_1 = 'action1';
      
      function run() {
        prepare(ACTION_1);
        execute(ACTION_1);
        release(ACTION_1);
      }
      

      Exceptions

      To prevent generating some false-positives, literals having less than 5 characters are excluded.

      Add curly braces around the nested statement(s).
      Open

              if (!is_null($cursor))

      While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

      Noncompliant Code Example

      if (condition)  // Noncompliant
        executeSomething();
      

      Compliant Solution

      if (condition) {
        executeSomething();
      }
      

      See

      • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
      • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
      • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
      • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
      • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

      There are no issues that match your filters.

      Category
      Status