SAREhub/PHP_Commons

View on GitHub

Showing 139 of 139 total issues

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

    public function dispatchSignal($signal)
    {
        if (isset($this->handlers[$signal])) {
            foreach ($this->handlers[$signal] as $namespaceHandlers) {
                foreach ($namespaceHandlers as $handler) {
Severity: Minor
Found in src/SAREhub/Commons/Process/PcntlSignals.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 receive has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function receive($wait = false)
    {
        if ($this->isBindedOrConnected()) {
            $mode = ($wait) ? 0 : \ZMQ::MODE_DONTWAIT;
            if ($parts = $this->getSocket()->recvMulti($mode)) {
Severity: Minor
Found in src/SAREhub/Commons/Zmq/PublishSubscribe/Subscriber.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

Avoid assigning values to variables in if clauses and the like (line '22', column '13').
Open

    public function create($creatorName, $data = null)
    {
        if ($creator = $this->getCreator($creatorName)) {
            return $creator($data);
        }

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

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

Avoid using static access to class '\Mockery' in method 'create'.
Open

        return \Mockery::mock(self::class);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid using static access to class 'SAREhub\Commons\Misc\EnvVarNotFoundException' in method 'getRequiredVar'.
Open

            throw EnvVarNotFoundException::create($name);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid unused parameters such as '$part'.
Open

    public static function isHashPart(string $part)

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Avoid unused parameters such as '$name'.
Open

    public function create($name)

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Avoid unused parameters such as '$namespace'.
Open

    public function getHandlersForSignal($signal, $namespace = null)

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Avoid unused parameters such as '$part'.
Open

    public static function isStarPart(string $part)

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Avoid using static access to class '\GuzzleHttp\HandlerStack' in method 'build'.
Open

            'handler' => HandlerStack::create(new MockHandler($this->responseQueue))

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid unused private fields such as '$timerCallback'.
Open

    private $timerCallback;

UnusedPrivateField

Since: 0.2

Detects when a private field is declared and/or assigned a value, but not used.

Example

class Something
{
    private static $FOO = 2; // Unused
    private $i = 5; // Unused
    private $j = 6;
    public function addOne()
    {
        return $this->j++;
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

Avoid using static access to class '\SAREhub\Commons\Misc\EnvironmentHelper' in method 'get'.
Open

        return EnvironmentHelper::getVar($this->envVar, self::DEFAULT_LOGGING_LEVEL);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid assigning values to variables in if clauses and the like (line '41', column '17').
Open

    public function receive($wait = false)
    {
        if ($this->isBindedOrConnected()) {
            $mode = ($wait) ? 0 : \ZMQ::MODE_DONTWAIT;
            if ($parts = $this->getSocket()->recvMulti($mode)) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

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

Avoid using static access to class 'SAREhub\Commons\Misc\ArrayHelper' in method 'createFlatten'.
Open

        return self::create(ArrayHelper::flatten($params));

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Line exceeds 120 characters; contains 126 characters
Open

            $createTableSql = "CREATE TABLE " . $this->tableName . "(id TEXT PRIMARY KEY, hash TEXT NOT NULL) WITHOUT ROWID;";

Line exceeds 120 characters; contains 151 characters
Open

    public function __construct(callable $callback, array $expectedErrorClasses = [], int $maxRetries = 3, float $initialWait = 1.0, int $exponent = 2)

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}
Severity: Minor
Found in examples/ExampleCommons.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

}
Severity
Category
Status
Source
Language