src/Persistence.php

Summary

Maintainability
D
2 days
Test Coverage

File Persistence.php has 336 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Atk4\Data;
Severity: Minor
Found in src/Persistence.php - About 4 hrs to fix

Function _typecastPreField has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    private function _typecastPreField(Field $field, $value, bool $fromLoad)
    {
        if (is_string($value)) {
            switch ($field->type) {
                case 'boolean':
Severity: Minor
Found in src/Persistence.php - About 3 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

Persistence has 21 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class Persistence
{
    use ContainerTrait {
        add as private _add;
    }
Severity: Minor
Found in src/Persistence.php - About 2 hrs to fix

Method _typecastPreField has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function _typecastPreField(Field $field, $value, bool $fromLoad)
    {
        if (is_string($value)) {
            switch ($field->type) {
                case 'boolean':
Severity: Minor
Found in src/Persistence.php - About 2 hrs to fix

Method _typecastLoadField has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function _typecastLoadField(Field $field, $value)
    {
        $value = $this->_typecastPreField($field, $value, true);

        // TODO casting optionally to null should be handled by type itself solely
Severity: Minor
Found in src/Persistence.php - About 1 hr to fix

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

    protected function _typecastLoadField(Field $field, $value)
    {
        $value = $this->_typecastPreField($field, $value, true);

        // TODO casting optionally to null should be handled by type itself solely
Severity: Minor
Found in src/Persistence.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 insert has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function insert(Model $model, array $data)
    {
        $model->assertIsModel();

        if ($model->idField && array_key_exists($model->idField, $data) && $data[$model->idField] === null) {
Severity: Minor
Found in src/Persistence.php - About 1 hr to fix

Function _typecastSaveField has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    protected function _typecastSaveField(Field $field, $value)
    {
        $value = $this->_typecastPreField($field, $value, false);

        if (in_array($field->type, ['json', 'object'], true) && $value === '') { // TODO remove later
Severity: Minor
Found in src/Persistence.php - About 55 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 typecastSaveField has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function typecastSaveField(Field $field, $value)
    {
        // SQL Expression cannot be converted
        if ($value instanceof Persistence\Sql\Expressionable) {
            return $value;
Severity: Minor
Found in src/Persistence.php - About 45 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 insert has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function insert(Model $model, array $data)
    {
        $model->assertIsModel();

        if ($model->idField && array_key_exists($model->idField, $data) && $data[$model->idField] === null) {
Severity: Minor
Found in src/Persistence.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

There are no issues that match your filters.

Category
Status