src/App/SessionManager.php

Summary

Maintainability
A
0 mins
Test Coverage

atomicSession accesses the super-global variable $_SESSION.
Open

    public function atomicSession(\Closure $fx, bool $readAndCloseImmediately = false)
    {
        $wasActive = $this->isSessionActive();

        if (!$wasActive) {
Severity: Minor
Found in src/App/SessionManager.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

atomicSession accesses the super-global variable $_SESSION.
Open

    public function atomicSession(\Closure $fx, bool $readAndCloseImmediately = false)
    {
        $wasActive = $this->isSessionActive();

        if (!$wasActive) {
Severity: Minor
Found in src/App/SessionManager.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

atomicSession accesses the super-global variable $_SESSION.
Open

    public function atomicSession(\Closure $fx, bool $readAndCloseImmediately = false)
    {
        $wasActive = $this->isSessionActive();

        if (!$wasActive) {
Severity: Minor
Found in src/App/SessionManager.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

memorize accesses the super-global variable $_SESSION.
Open

    public function memorize(string $namespace, string $key, $value)
    {
        return $this->atomicSession(function () use ($namespace, $key, $value) {
            $_SESSION[$this->rootNamespace][$namespace][$key] = $value;

Severity: Minor
Found in src/App/SessionManager.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

forget accesses the super-global variable $_SESSION.
Open

    public function forget(string $namespace, ?string $key = null): void
    {
        $this->atomicSession(function () use ($namespace, $key) {
            if ($key === null) {
                unset($_SESSION[$this->rootNamespace][$namespace]);
Severity: Minor
Found in src/App/SessionManager.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

forget accesses the super-global variable $_SESSION.
Open

    public function forget(string $namespace, ?string $key = null): void
    {
        $this->atomicSession(function () use ($namespace, $key) {
            if ($key === null) {
                unset($_SESSION[$this->rootNamespace][$namespace]);
Severity: Minor
Found in src/App/SessionManager.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Avoid using undefined variables such as '$found' which will lead to PHP notices.
Open

        if ($found) {
Severity: Minor
Found in src/App/SessionManager.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$found' which will lead to PHP notices.
Open

        if ($found) {
Severity: Minor
Found in src/App/SessionManager.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$found' which will lead to PHP notices.
Open

        $res = $this->recallWithCache($namespace, $key, $found);
Severity: Minor
Found in src/App/SessionManager.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$found' which will lead to PHP notices.
Open

        $res = $this->recallWithCache($namespace, $key, $found);
Severity: Minor
Found in src/App/SessionManager.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$found' which will lead to PHP notices.
Open

            $res = $this->recallWithCache($namespace, $key, $found);
Severity: Minor
Found in src/App/SessionManager.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

Avoid using undefined variables such as '$found' which will lead to PHP notices.
Open

            if ($found) {
Severity: Minor
Found in src/App/SessionManager.php by phpmd

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

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

The method atomicSession has a boolean flag argument $readAndCloseImmediately, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function atomicSession(\Closure $fx, bool $readAndCloseImmediately = false)
Severity: Minor
Found in src/App/SessionManager.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

The method closeSession uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $res = session_abort();
        }
Severity: Minor
Found in src/App/SessionManager.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

The method forget uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                unset($_SESSION[$this->rootNamespace][$namespace][$key]);
            }
Severity: Minor
Found in src/App/SessionManager.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid excessively long variable names like $readAndCloseImmediately. Keep variable name length under 20.
Open

    protected function startSession(bool $readAndCloseImmediately): void
Severity: Minor
Found in src/App/SessionManager.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

Avoid excessively long variable names like $readAndCloseImmediately. Keep variable name length under 20.
Open

    public function atomicSession(\Closure $fx, bool $readAndCloseImmediately = false)
Severity: Minor
Found in src/App/SessionManager.php by phpmd

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

Avoid variables with short names like $e. Configured minimum length is 3.
Open

        $e = null;
Severity: Minor
Found in src/App/SessionManager.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Avoid variables with short names like $fx. Configured minimum length is 3.
Open

    public function atomicSession(\Closure $fx, bool $readAndCloseImmediately = false)
Severity: Minor
Found in src/App/SessionManager.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

Closing brace must be on a line by itself
Open

            $this->atomicSession(static function (): void {}, true);
Severity: Minor
Found in src/App/SessionManager.php by phpcodesniffer

There are no issues that match your filters.

Category
Status