rtckit/php-pcap-ffi

View on GitHub

Showing 11 of 11 total issues

Function activateSession has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

    private function activateSession(): ?CData
    {
        if (isset($this->context)) {
            $context = stream_context_get_options($this->context);

Severity: Minor
Found in src/StreamWrapper.php - 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

Method activateSession has 53 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function activateSession(): ?CData
    {
        if (isset($this->context)) {
            $context = stream_context_get_options($this->context);

Severity: Major
Found in src/StreamWrapper.php - About 2 hrs to fix

    Function stream_open has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        public function stream_open(string $path, string $mode, ?int $options, ?string &$opened_path): bool
        {
            if (extension_loaded('sockets')) {
                $raw = @\socket_create(AF_INET, SOCK_RAW, SOL_TCP);
    
    
    Severity: Minor
    Found in src/StreamWrapper.php - About 2 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 stream_open has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function stream_open(string $path, string $mode, ?int $options, ?string &$opened_path): bool
        {
            if (extension_loaded('sockets')) {
                $raw = @\socket_create(AF_INET, SOCK_RAW, SOL_TCP);
    
    
    Severity: Minor
    Found in src/StreamWrapper.php - About 1 hr to fix

      Method stream_cast has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function stream_cast(int $cast_as)
          {
              if (is_null($this->pcap) && (($this->pcap = $this->activateSession()) === null)) {
                  return false;
              }
      Severity: Minor
      Found in src/StreamWrapper.php - About 1 hr to fix

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

            public function stream_read(int $count): string
            {
                if (is_null($this->pcap) && (($this->pcap = $this->activateSession()) === null)) {
                    return '';
                }
        Severity: Minor
        Found in src/StreamWrapper.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 stream_cast has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public function stream_cast(int $cast_as)
            {
                if (is_null($this->pcap) && (($this->pcap = $this->activateSession()) === null)) {
                    return false;
                }
        Severity: Minor
        Found in src/StreamWrapper.php - About 35 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 __construct has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            public function __construct()
            {
                if (isset(self::$ffi)) {
                    return;
                }
        Severity: Minor
        Found in src/PcapFFI.php - About 35 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

        Avoid too many return statements within this method.
        Open

                return false;
        Severity: Major
        Found in src/StreamWrapper.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          return $this->fp;
          Severity: Major
          Found in src/StreamWrapper.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return true;
            Severity: Major
            Found in src/StreamWrapper.php - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language