symplely/coroutine

View on GitHub
Coroutine/Networks.php

Summary

Maintainability
F
5 days
Test Coverage

File Networks.php has 529 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Async;
Severity: Major
Found in Coroutine/Networks.php - About 1 day to fix

    Function client has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

      public static function client($uri = null, OptionsInterface $context = null)
      {
        [$parts, $uri, $ip,] = yield net_getaddrinfo((string)$uri);
        $isSSL = \in_array($parts['scheme'], ['https', 'wss', 'tls', 'ssl']) || $parts['port'] === 443
          || ($context instanceof SSLContext);
    Severity: Minor
    Found in Coroutine/Networks.php - About 7 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 client has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public static function client($uri = null, OptionsInterface $context = null)
      {
        [$parts, $uri, $ip,] = yield net_getaddrinfo((string)$uri);
        $isSSL = \in_array($parts['scheme'], ['https', 'wss', 'tls', 'ssl']) || $parts['port'] === 443
          || ($context instanceof SSLContext);
    Severity: Major
    Found in Coroutine/Networks.php - About 2 hrs to fix

      Method listen has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public static function listen($server, int $listenerTask, int $backlog = 0)
        {
          if (self::isUv() && ($server instanceof \UVStream || $server instanceof \UVUdp)) {
            return yield new Kernel(
              function (TaskInterface $task, CoroutineInterface $coroutine) use ($server, $listenerTask, $backlog) {
      Severity: Minor
      Found in Coroutine/Networks.php - About 1 hr to fix

        Function server has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          public static function server(
            $uri,
            ?OptionsInterface $context = null,
            ?string $capath = None,
            ?string $cafile = None,
        Severity: Minor
        Found in Coroutine/Networks.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 server has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public static function server(
            $uri,
            ?OptionsInterface $context = null,
            ?string $capath = None,
            ?string $cafile = None,
        Severity: Minor
        Found in Coroutine/Networks.php - About 1 hr to fix

          Function listen has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            public static function listen($server, int $listenerTask, int $backlog = 0)
            {
              if (self::isUv() && ($server instanceof \UVStream || $server instanceof \UVUdp)) {
                return yield new Kernel(
                  function (TaskInterface $task, CoroutineInterface $coroutine) use ($server, $listenerTask, $backlog) {
          Severity: Minor
          Found in Coroutine/Networks.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 connect has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public static function connect(string $scheme, string $address, int $port, $data = null)
            {
              return new Kernel(
                function (TaskInterface $task, CoroutineInterface $coroutine) use ($scheme, $address, $port, $data) {
                  $callback =  function ($client, $status) use ($task, $coroutine) {
          Severity: Minor
          Found in Coroutine/Networks.php - About 1 hr to fix

            Method accept has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public static function accept($server)
              {
                if (self::isUv() && $server instanceof \UV) {
                  return yield new Kernel(
                    function (TaskInterface $task, CoroutineInterface $coroutine) use ($server) {
            Severity: Minor
            Found in Coroutine/Networks.php - About 1 hr to fix

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

                public static function read($handle, $size = -1)
                {
                  if (self::isUv() && $handle instanceof \UV) {
                    if (\uv_is_closing($handle))
                      return false;
              Severity: Minor
              Found in Coroutine/Networks.php - About 1 hr to fix

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

                  public static function bind(string $scheme, string $address, int $port)
                  {
                    $uv = \coroutine()->getUV();
                    $ip = (\strpos($address, ':') === false)
                      ? \uv_ip4_addr($address, $port)
                Severity: Minor
                Found in Coroutine/Networks.php - About 1 hr to fix

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

                    public static function write($handle, $data = '')
                    {
                      if (self::isUv() && $handle instanceof \UV) {
                        if (\uv_is_closing($handle))
                          return false;
                  Severity: Minor
                  Found in Coroutine/Networks.php - About 1 hr to fix

                    Avoid deeply nested control flow statements.
                    Open

                                  if ($enabled === false)
                                    throw new \RuntimeException(\sprintf('Failed to enable socket encryption: %s', \error_get_last()['message'] ?? ''));
                    Severity: Major
                    Found in Coroutine/Networks.php - About 45 mins to fix

                      Function read has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        public static function read($handle, $size = -1)
                        {
                          if (self::isUv() && $handle instanceof \UV) {
                            if (\uv_is_closing($handle))
                              return false;
                      Severity: Minor
                      Found in Coroutine/Networks.php - 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

                      Function write has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        public static function write($handle, $data = '')
                        {
                          if (self::isUv() && $handle instanceof \UV) {
                            if (\uv_is_closing($handle))
                              return false;
                      Severity: Minor
                      Found in Coroutine/Networks.php - 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

                      Function listenerTask has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        public static function listenerTask(callable $handler)
                        {
                          return Kernel::away(function () use ($handler) {
                            $coroutine = \coroutine();
                            $tid = yield \stateless_task();
                      Severity: Minor
                      Found in Coroutine/Networks.php - 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

                      Avoid deeply nested control flow statements.
                      Open

                                    if ($enabled === true)
                                      break;
                      Severity: Major
                      Found in Coroutine/Networks.php - About 45 mins to fix

                        Method server has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            $uri,
                            ?OptionsInterface $context = null,
                            ?string $capath = None,
                            ?string $cafile = None,
                            array $caSelfDetails = []
                        Severity: Minor
                        Found in Coroutine/Networks.php - About 35 mins to fix

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

                            public static function connect(string $scheme, string $address, int $port, $data = null)
                            {
                              return new Kernel(
                                function (TaskInterface $task, CoroutineInterface $coroutine) use ($scheme, $address, $port, $data) {
                                  $callback =  function ($client, $status) use ($task, $coroutine) {
                          Severity: Minor
                          Found in Coroutine/Networks.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

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

                            public static function accept($server)
                            {
                              if (self::isUv() && $server instanceof \UV) {
                                return yield new Kernel(
                                  function (TaskInterface $task, CoroutineInterface $coroutine) use ($server) {
                          Severity: Minor
                          Found in Coroutine/Networks.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

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

                            public static function peer($handle)
                            {
                              if ($handle instanceof \UVTcp) {
                                $peer = \uv_tcp_getpeername($handle);
                                return $peer['address'] . ':' . $peer['port'];
                          Severity: Major
                          Found in Coroutine/Networks.php and 1 other location - About 1 hr to fix
                          Coroutine/Networks.php on lines 697..711

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

                          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

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

                            public static function local($handle)
                            {
                              if ($handle instanceof \UVTcp) {
                                $local = \uv_tcp_getsockname($handle);
                                return $local['address'] . ':' . $local['port'];
                          Severity: Major
                          Found in Coroutine/Networks.php and 1 other location - About 1 hr to fix
                          Coroutine/Networks.php on lines 675..689

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

                          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

                          There are no issues that match your filters.

                          Category
                          Status