File Coroutine.php
has 965 lines of code (exceeds 250 allowed). Consider refactoring. Wontfix
<?php
declare(strict_types=1);
namespace Async;
Coroutine
has 70 functions (exceeds 20 allowed). Consider refactoring. Wontfix
final class Coroutine implements CoroutineInterface
{
/**
* checker for main supervisor task running state
*
Function execute
has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring. Open
public function execute($isReturn = false)
{
while (!$this->taskQueue->isEmpty()) {
/** @var TaskInterface|FiberInterface */
$task = $this->taskQueue->dequeue();
- Read upRead up
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 create
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public static function create(\Generator $gen)
{
$stack = new \SplStack;
$exception = null;
- Read upRead up
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 close
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public function close()
{
if ($this->uv instanceof \UVLoop) {
foreach ($this->timers as $timer) {
if ($timer instanceof \UVTimer && \uv_is_active($timer))
- Read upRead up
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 execute
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
public function execute($isReturn = false)
{
while (!$this->taskQueue->isEmpty()) {
/** @var TaskInterface|FiberInterface */
$task = $this->taskQueue->dequeue();
Function input
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function input(int $size = 256, bool $error = false)
{
//Check on STDIN stream
$blocking = \stream_set_blocking(\STDIN, false);
if ($error && !$blocking) {
- Read upRead up
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 shutdown
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function shutdown(?int $skipTask = 1)
{
if ($skipTask === 1)
$skipTask = Co::getUnique('parent');
- Read upRead up
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 close
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
public function close()
{
if ($this->uv instanceof \UVLoop) {
foreach ($this->timers as $timer) {
if ($timer instanceof \UVTimer && \uv_is_active($timer))
Method create
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
public static function create(\Generator $gen)
{
$stack = new \SplStack;
$exception = null;
Method __construct
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
public function __construct()
{
$this->maxTaskId = Co::getUnique('dirty') === 1 ? Co::getUnique('max') : \random_int(10000, 9999999999);
Co::reset();
Co::setLoop($this);
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);
- Read upRead up
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;
}
- Read upRead up
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 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);
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);
Function cancelProgress
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function cancelProgress(TaskInterface $task)
{
$channel = $task->getCustomState();
if (\is_array($channel) && (\count($channel) == 2)) {
[$channel, $channelTask] = $channel;
- Read upRead up
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 removeSignal
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function removeSignal($signal, $listener)
{
if (!$this->signaler || !$this->signaler->count($signal))
return;
- Read upRead up
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 addTimeout
has a Cognitive Complexity of 11 (exceeds 5 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);
- Read upRead up
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 executeFiber
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function executeFiber(Fiber $fiber)
{
// Skip and reschedule, if `fiber` in suspend state
if ($fiber->isSuspended())
return $this->scheduleFiber($fiber);
- Read upRead up
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 ioSocketStream
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
protected function ioSocketStream($timeout)
{
if (empty($this->waitingForRead) && empty($this->waitingForWrite)) {
return;
}
Function clearTimeout
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function clearTimeout(TaskInterface $task): void
{
$timer = $task->getTimer();
if ($this->isUv() && $timer instanceof \UVTimer && \uv_is_active($timer)) {
@\uv_timer_stop($timer);
- Read upRead up
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 updateCompleted
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function updateCompleted(
int $taskId,
array $completeList = [],
?callable $onClear = null,
bool $cancel = false,
- Read upRead up
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 (!$this->future->isEmpty())
continue;
Function addEvent
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function addEvent($stream)
{
if (!isset($this->events[(int) $stream])) {
$meta = \stream_get_meta_data($stream);
switch ($meta['stream_type'] ?? '') {
- Read upRead up
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 ioWaiting
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function ioWaiting()
{
$isUv = $this->isUv();
while (true) {
if ($this->isCoroutinesDone()) {
- Read upRead up
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 updateCompleted
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
int $taskId,
array $completeList = [],
?callable $onClear = null,
bool $cancel = false,
bool $forceUpdate = false
Function addSignal
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function addSignal($signal, $listener)
{
if (!$this->signaler)
return;
- Read upRead up
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 ioSocketStream
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function ioSocketStream($timeout)
{
if (empty($this->waitingForRead) && empty($this->waitingForWrite)) {
return;
}
- Read upRead up
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 updateScheduler
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function updateScheduler(string $type, $stream, bool $removeEvent = false)
{
if ($type == 'read') {
list(, $tasks) = $this->waitingForRead[(int) $stream];
$this->removeReader($stream, $removeEvent);
- Read upRead up
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 function addReader($stream, $task, bool $addEvent = true): CoroutineInterface
{
$already = true;
if (isset($this->waitingForRead[(int) $stream])) {
$already = false;
- Read upRead up
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 137.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function addWriter($stream, $task, bool $addEvent = true): CoroutineInterface
{
$already = true;
if (isset($this->waitingForWrite[(int) $stream])) {
$already = false;
- Read upRead up
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 137.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Wontfix
protected function removeWriteEvent($stream)
{
if (!isset($this->events[(int) $stream])) {
return;
}
- Read upRead up
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 107.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Wontfix
protected function removeReadEvent($stream)
{
if (!isset($this->events[(int) $stream])) {
return;
}
- Read upRead up
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 107.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76