symplely/coroutine

View on GitHub

Showing 209 of 236 total issues

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

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

  public function run()
  {
    if ($this->beforeFirstYield) {
      $this->beforeFirstYield = false;
      return ($this->coroutine instanceof \Generator)
Severity: Minor
Found in Coroutine/Task.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

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

  public function commit()
  {
    if (\is_array($this->loggerTaskId) && (\count($this->loggerTaskId) > 0)) {
      foreach (\range(0, \count($this->loggerTaskId)) as $nan)
        yield;
Severity: Minor
Found in Coroutine/Logger/AsyncLogger.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

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

  public static function away($label, ...$args)
  {
    if (\is_string($label) && Co::isFunction($label)) {
      return Kernel::createTask(Co::getFunction($label)(...$args), true);
    }
Severity: Minor
Found in Coroutine/Kernel.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

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

  public function cancelTask(int $tid, $customState = null, string $errorMessage = 'Invalid task ID!')
  {
    if (!isset($this->taskMap[$tid])) {
      return false;
    }
Severity: Minor
Found in Coroutine/Coroutine.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

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

  public function __construct()
  {
    $this->maxTaskId = Co::getUnique('dirty') === 1 ? Co::getUnique('max') : \random_int(10000, 9999999999);
    Co::reset();
    Co::setLoop($this);
Severity: Minor
Found in Coroutine/Coroutine.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

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

Method executeFiber has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  protected function executeFiber(Fiber $fiber)
  {
    // Skip and reschedule, if `fiber` in suspend state
    if ($fiber->isSuspended())
      return $this->scheduleFiber($fiber);
Severity: Minor
Found in Coroutine/Coroutine.php - About 1 hr to fix

    Function throwable has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      protected static function throwable(\Throwable $error, CoroutineInterface $coroutine)
      {
        yield;
        $task = $coroutine->getTask(yield \current_task());
        $task->setState(
    Severity: Minor
    Found in Coroutine/Kernel.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

    Function elements has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      protected function elements(...$items): array
      {
        $elements = [];
        if (\is_iterable($items)) {
          $items = isset($items[0]) && \is_array($items[0]) ? $items[0] : $items;
    Severity: Minor
    Found in Coroutine/Misc/Datatype/Lists.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

    Function interpolate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      private static function interpolate($string, array $vars)
      {
        if (!\preg_match_all("~\{([\w\.]+)\}~", $string, $matches, \PREG_SET_ORDER)) {
          return $string;
        }
    Severity: Minor
    Found in Coroutine/Logger/Logger.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 adding has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public function adding(?\closure $future = null, ?string $include = null, ...$args): FutureInterface
        {
          $defined = Globals::get();
      
          if (!\is_callable($future) && !$future instanceof FutureInterface) {
      Severity: Minor
      Found in Coroutine/Parallel.php - About 1 hr to fix

        Method create_default_context has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public static function create_default_context(
            string $purpose,
            ?string $name = None,
            $context = [],
            ?string $capath = None,
        Severity: Minor
        Found in Coroutine/Misc/Network/SSLContext.php - About 1 hr to fix

          Method parse has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public function parse($headers)
            {
              $this->headers = [];
              $this->parameters = [];
              $this->path = '';
          Severity: Minor
          Found in Coroutine/SocketMessage.php - About 1 hr to fix

            Method addTimeout has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public function addTimeout($task = null, float $timeout = 0.0, int $tid = null)
              {
                if ($this->isUv()) {
                  $interval = (int) \round($timeout * 1000);
                  $timer = \uv_timer_init($this->uv);
            Severity: Minor
            Found in Coroutine/Coroutine.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

                Function setWriter has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  public function setWriter(callable $writer = null, $levels = self::ALL, $interval = 1, callable $formatter = null)
                  {
                    if (empty($formatter)) {
                      $formatter = $this->defaultFormatter;
                    }
                Severity: Minor
                Found in Coroutine/Logger/Logger.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

                Function result has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  public function result()
                  {
                    if ($this->isCompleted()) {
                      $result = $this->result;
                      if ($this->customData instanceof FutureInterface)
                Severity: Minor
                Found in Coroutine/Task.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

                Severity
                Category
                Status
                Source
                Language