marcelog/PAMI

View on GitHub
src/PAMI/Client/Impl/ClientImpl.php

Summary

Maintainability
B
5 hrs
Test Coverage
A
98%

The class ClientImpl has 16 fields. Consider redesigning ClientImpl to keep the number of fields under 15.
Open

class ClientImpl implements IClient
{
    /**
     * PSR-3 logger.
     * @var LoggerInterface
Severity: Minor
Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

TooManyFields

Since: 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example

class Person {
   protected $one;
   private $two;
   private $three;
   [... many more fields ...]
}

Source https://phpmd.org/rules/codesize.html#toomanyfields

Function process has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function process()
    {
        $msgs = $this->getMessages();
        foreach ($msgs as $aMsg) {
            $this->logger->debug(
Severity: Minor
Found in src/PAMI/Client/Impl/ClientImpl.php - 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 open has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function open()
    {
        $cString = $this->scheme . $this->host . ':' . $this->port;
        $this->context = stream_context_create();
        $errno = 0;
Severity: Minor
Found in src/PAMI/Client/Impl/ClientImpl.php - About 1 hr to fix

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

        public function process()
        {
            $msgs = $this->getMessages();
            foreach ($msgs as $aMsg) {
                $this->logger->debug(
    Severity: Minor
    Found in src/PAMI/Client/Impl/ClientImpl.php - About 1 hr to fix

      Function dispatch has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function dispatch(IncomingMessage $message)
          {
              foreach ($this->eventListeners as $data) {
                  $listener = $data[0];
                  $predicate = $data[1];
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php - About 55 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

      Function send has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function send(OutgoingMessage $message)
          {
              $messageToSend = $message->serialize();
              $length = strlen($messageToSend);
              $this->logger->debug(
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php - 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

      Remove error control operator '@' on line 169.
      Open

          public function open()
          {
              $cString = $this->scheme . $this->host . ':' . $this->port;
              $this->context = stream_context_create();
              $errno = 0;
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ErrorControlOperator

      Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

      Example

      function foo($filePath) {
          $file = @fopen($filPath); // hides exceptions
          $key = @$array[$notExistingKey]; // assigns null to $key
      }

      Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

      Remove error control operator '@' on line 435.
      Open

          public function close()
          {
              $this->logger->debug('Closing connection to asterisk.');
              @stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
          }
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ErrorControlOperator

      Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

      Example

      function foo($filePath) {
          $file = @fopen($filPath); // hides exceptions
          $key = @$array[$notExistingKey]; // assigns null to $key
      }

      Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

      Remove error control operator '@' on line 240.
      Open

          protected function getMessages()
          {
              $msgs = array();
              // Read something.
              $read = @fread($this->socket, 65535);
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ErrorControlOperator

      Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

      Example

      function foo($filePath) {
          $file = @fopen($filPath); // hides exceptions
          $key = @$array[$notExistingKey]; // assigns null to $key
      }

      Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

      Remove error control operator '@' on line 193.
      Open

          public function open()
          {
              $cString = $this->scheme . $this->host . ':' . $this->port;
              $this->context = stream_context_create();
              $errno = 0;
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ErrorControlOperator

      Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

      Example

      function foo($filePath) {
          $file = @fopen($filPath); // hides exceptions
          $key = @$array[$notExistingKey]; // assigns null to $key
      }

      Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

      Remove error control operator '@' on line 181.
      Open

          public function open()
          {
              $cString = $this->scheme . $this->host . ':' . $this->port;
              $this->context = stream_context_create();
              $errno = 0;
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ErrorControlOperator

      Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

      Example

      function foo($filePath) {
          $file = @fopen($filPath); // hides exceptions
          $key = @$array[$notExistingKey]; // assigns null to $key
      }

      Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

      Remove error control operator '@' on line 241.
      Open

          protected function getMessages()
          {
              $msgs = array();
              // Read something.
              $read = @fread($this->socket, 65535);
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ErrorControlOperator

      Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

      Example

      function foo($filePath) {
          $file = @fopen($filPath); // hides exceptions
          $key = @$array[$notExistingKey]; // assigns null to $key
      }

      Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

      Remove error control operator '@' on line 408.
      Open

          public function send(OutgoingMessage $message)
          {
              $messageToSend = $message->serialize();
              $length = strlen($messageToSend);
              $this->logger->debug(
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ErrorControlOperator

      Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

      Example

      function foo($filePath) {
          $file = @fopen($filPath); // hides exceptions
          $key = @$array[$notExistingKey]; // assigns null to $key
      }

      Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

      The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                      } else {
                          $response->addEvent($event);
                      }
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      // broken ami.. sending a response with events without
                      // Event and ActionId
                      $bMsg = 'Event: ResponseEvent' . "\r\n";
                      $bMsg .= 'ActionId: ' . $this->lastActionId . "\r\n" . $aMsg;
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      The method dispatch uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $listener->handle($message);
                  }
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid excessively long variable names like $currentProcessingMessage. Keep variable name length under 20.
      Open

          private $currentProcessingMessage;
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#longvariable

      Avoid variables with short names like $id. Configured minimum length is 3.
      Open

              $id = $message->getActionID('ActionID');
      Severity: Minor
      Found in src/PAMI/Client/Impl/ClientImpl.php by phpmd

      ShortVariable

      Since: 0.2

      Detects when a field, local, or parameter has a very short name.

      Example

      class Something {
          private $q = 15; // VIOLATION - Field
          public static function main( array $as ) { // VIOLATION - Formal
              $r = 20 + $this->q; // VIOLATION - Local
              for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                  $r += $this->q;
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#shortvariable

      There are no issues that match your filters.

      Category
      Status