src/Persistence/Sql/Expression.php

Summary

Maintainability
F
3 days
Test Coverage

File Expression.php has 512 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Atk4\Data\Persistence\Sql;
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 1 day to fix

Function _execute has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _execute(?object $connection, bool $fromExecuteStatement)
    {
        if ($connection === null) {
            $connection = $this->connection;
        }
Severity: Minor
Found in src/Persistence/Sql/Expression.php - About 5 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

Expression has 32 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class Expression implements Expressionable, \ArrayAccess
{
    use DiContainerTrait;

    private static ?SqlFormatter $debugFormatter = null;
Severity: Minor
Found in src/Persistence/Sql/Expression.php - About 4 hrs to fix

Method _execute has 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function _execute(?object $connection, bool $fromExecuteStatement)
    {
        if ($connection === null) {
            $connection = $this->connection;
        }
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 2 hrs to fix

Method getDebugQuery has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getDebugQuery(): string
    {
        [$sql, $params] = $this->render();

        $i = 0;
Severity: Minor
Found in src/Persistence/Sql/Expression.php - About 1 hr to fix

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

    private function _render(): array
    {
        // - [xxx] = param
        // - {xxx} = escape
        // - {{xxx}} = escapeSoft
Severity: Minor
Found in src/Persistence/Sql/Expression.php - About 1 hr to fix

Method consume has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function consume($expr, string $escapeMode): string
    {
        if (!is_object($expr)) {
            switch ($escapeMode) {
                case self::ESCAPE_PARAM:
Severity: Minor
Found in src/Persistence/Sql/Expression.php - About 1 hr to fix

Function castGetValue has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    private function castGetValue($v): ?string
    {
        if (is_bool($v)) {
            return $v ? '1' : '0';
        } elseif (is_int($v)) {
Severity: Minor
Found in src/Persistence/Sql/Expression.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 consume has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    protected function consume($expr, string $escapeMode): string
    {
        if (!is_object($expr)) {
            switch ($escapeMode) {
                case self::ESCAPE_PARAM:
Severity: Minor
Found in src/Persistence/Sql/Expression.php - About 35 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 too many return statements within this method.
Open

                return $k;
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return $this->escapeStringLiteral($v);
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                    return $matches[0];
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return $sql;
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                    return (string) $v;
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                    return self::castFloatToString($v);
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                    return '*long string* (length: ' . strlen($v) . ' bytes, sha256: ' . hash('sha256', $v) . ')';
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return $sql;
Severity: Major
Found in src/Persistence/Sql/Expression.php - About 30 mins to fix

There are no issues that match your filters.

Category
Status